• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3  *           (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  */
21 
22 #include "config.h"
23 #include "RenderTextControlMultiLine.h"
24 
25 #include "EventNames.h"
26 #include "Frame.h"
27 #include "HitTestResult.h"
28 #include "HTMLTextAreaElement.h"
29 #ifdef ANDROID_LAYOUT
30 #include "Settings.h"
31 #endif
32 
33 namespace WebCore {
34 
RenderTextControlMultiLine(Node * node)35 RenderTextControlMultiLine::RenderTextControlMultiLine(Node* node)
36     : RenderTextControl(node)
37 {
38 }
39 
~RenderTextControlMultiLine()40 RenderTextControlMultiLine::~RenderTextControlMultiLine()
41 {
42     if (node())
43         static_cast<HTMLTextAreaElement*>(node())->rendererWillBeDestroyed();
44 }
45 
subtreeHasChanged()46 void RenderTextControlMultiLine::subtreeHasChanged()
47 {
48     RenderTextControl::subtreeHasChanged();
49     static_cast<Element*>(node())->setFormControlValueMatchesRenderer(false);
50 
51     if (!node()->focused())
52         return;
53 
54     // Fire the "input" DOM event
55     node()->dispatchEvent(eventNames().inputEvent, true, false);
56 
57     if (Frame* frame = document()->frame())
58         frame->textDidChangeInTextArea(static_cast<Element*>(node()));
59 }
60 
nodeAtPoint(const HitTestRequest & request,HitTestResult & result,int x,int y,int tx,int ty,HitTestAction hitTestAction)61 bool RenderTextControlMultiLine::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int x, int y, int tx, int ty, HitTestAction hitTestAction)
62 {
63     if (!RenderTextControl::nodeAtPoint(request, result, x, y, tx, ty, hitTestAction))
64         return false;
65 
66     if (result.innerNode() == node() || result.innerNode() == innerTextElement())
67         hitInnerTextElement(result, x, y, tx, ty);
68 
69     return true;
70 }
71 
forwardEvent(Event * event)72 void RenderTextControlMultiLine::forwardEvent(Event* event)
73 {
74     RenderTextControl::forwardEvent(event);
75 }
76 
preferredContentWidth(float charWidth) const77 int RenderTextControlMultiLine::preferredContentWidth(float charWidth) const
78 {
79     int factor = static_cast<HTMLTextAreaElement*>(node())->cols();
80     return static_cast<int>(ceilf(charWidth * factor)) + scrollbarThickness();
81 }
82 
adjustControlHeightBasedOnLineHeight(int lineHeight)83 void RenderTextControlMultiLine::adjustControlHeightBasedOnLineHeight(int lineHeight)
84 {
85     setHeight(height() + lineHeight * static_cast<HTMLTextAreaElement*>(node())->rows());
86 }
87 
baselinePosition(bool,bool) const88 int RenderTextControlMultiLine::baselinePosition(bool, bool) const
89 {
90     return height() + marginTop() + marginBottom();
91 }
92 
updateFromElement()93 void RenderTextControlMultiLine::updateFromElement()
94 {
95     createSubtreeIfNeeded(0);
96     RenderTextControl::updateFromElement();
97 
98     setInnerTextValue(static_cast<HTMLTextAreaElement*>(node())->value());
99 }
100 
cacheSelection(int start,int end)101 void RenderTextControlMultiLine::cacheSelection(int start, int end)
102 {
103     static_cast<HTMLTextAreaElement*>(node())->cacheSelection(start, end);
104 }
105 
createInnerTextStyle(const RenderStyle * startStyle) const106 PassRefPtr<RenderStyle> RenderTextControlMultiLine::createInnerTextStyle(const RenderStyle* startStyle) const
107 {
108     RefPtr<RenderStyle> textBlockStyle = RenderStyle::create();
109     textBlockStyle->inheritFrom(startStyle);
110 
111     adjustInnerTextStyle(startStyle, textBlockStyle.get());
112     textBlockStyle->setDisplay(BLOCK);
113 
114     return textBlockStyle.release();
115 }
116 
117 }
118