2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "HTMLInputElement.h"
34 #include "V8Binding.h"
35 #include "V8CustomBinding.h"
40 ACCESSOR_GETTER(HTMLInputElementSelectionStart)
42 INC_STATS("DOM.HTMLInputElement.selectionStart._get");
43 v8::Handle<v8::Object> holder = info.Holder();
44 HTMLInputElement* imp = V8Proxy::DOMWrapperToNode<HTMLInputElement>(holder);
46 if (!imp->canHaveSelection())
47 return throwError("Accessing selectionStart on an input element that cannot have a selection.");
49 int v = imp->selectionStart();
50 return v8::Integer::New(v);
53 ACCESSOR_SETTER(HTMLInputElementSelectionStart)
55 INC_STATS("DOM.HTMLInputElement.selectionStart._set");
56 v8::Handle<v8::Object> holder = info.Holder();
57 HTMLInputElement* imp = V8Proxy::DOMWrapperToNode<HTMLInputElement>(holder);
59 if (!imp->canHaveSelection()) {
60 throwError("Accessing selectionStart on an input element that cannot have a selection.");
63 imp->setSelectionStart(value->Int32Value());
66 ACCESSOR_GETTER(HTMLInputElementSelectionEnd)
68 INC_STATS("DOM.HTMLInputElement.selectionEnd._get");
69 v8::Handle<v8::Object> holder = info.Holder();
70 HTMLInputElement* imp = V8Proxy::DOMWrapperToNode<HTMLInputElement>(holder);
72 if (!imp->canHaveSelection())
73 return throwError("Accessing selectionEnd on an input element that cannot have a selection.");
75 int v = imp->selectionEnd();
76 return v8::Integer::New(v);
79 ACCESSOR_SETTER(HTMLInputElementSelectionEnd)
81 INC_STATS("DOM.HTMLInputElement.selectionEnd._set");
82 v8::Handle<v8::Object> holder = info.Holder();
83 HTMLInputElement* imp = V8Proxy::DOMWrapperToNode<HTMLInputElement>(holder);
85 if (!imp->canHaveSelection()) {
86 throwError("Accessing selectionEnd on an input element that cannot have a selection.");
90 imp->setSelectionEnd(value->Int32Value());
93 CALLBACK_FUNC_DECL(HTMLInputElementSetSelectionRange)
95 INC_STATS("DOM.HTMLInputElement.setSelectionRange");
96 v8::Handle<v8::Object> holder = args.Holder();
97 HTMLInputElement* imp = V8Proxy::DOMWrapperToNode<HTMLInputElement>(holder);
99 if (!imp->canHaveSelection())
100 return throwError("Calling setSelectionRange on an input element that cannot have a selection.");
102 int start = args[0]->Int32Value();
103 int end = args[1]->Int32Value();
105 imp->setSelectionRange(start, end);
106 return v8::Undefined();
109 } // namespace WebCore