Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(601)

Side by Side Diff: Source/core/platform/chromium/PopupContainer.cpp

Issue 15697018: Fix style errors in PopupContainer and PopupListBox. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011, Google Inc. All rights reserved. 2 * Copyright (c) 2011, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/platform/chromium/PopupContainer.h" 32 #include "core/platform/chromium/PopupContainer.h"
33 33
34 #include <limits>
35 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
36 #include "core/dom/UserGestureIndicator.h" 35 #include "core/dom/UserGestureIndicator.h"
37 #include "core/page/Chrome.h" 36 #include "core/page/Chrome.h"
38 #include "core/page/ChromeClient.h" 37 #include "core/page/ChromeClient.h"
39 #include "core/page/Frame.h" 38 #include "core/page/Frame.h"
40 #include "core/page/FrameView.h" 39 #include "core/page/FrameView.h"
41 #include "core/page/Page.h" 40 #include "core/page/Page.h"
42 #include "core/platform/PlatformGestureEvent.h" 41 #include "core/platform/PlatformGestureEvent.h"
43 #include "core/platform/PlatformKeyboardEvent.h" 42 #include "core/platform/PlatformKeyboardEvent.h"
44 #include "core/platform/PlatformMouseEvent.h" 43 #include "core/platform/PlatformMouseEvent.h"
45 #include "core/platform/PlatformScreen.h" 44 #include "core/platform/PlatformScreen.h"
46 #include "core/platform/PlatformTouchEvent.h" 45 #include "core/platform/PlatformTouchEvent.h"
47 #include "core/platform/PlatformWheelEvent.h" 46 #include "core/platform/PlatformWheelEvent.h"
48 #include "core/platform/PopupMenuClient.h" 47 #include "core/platform/PopupMenuClient.h"
49 #include "core/platform/chromium/FramelessScrollView.h" 48 #include "core/platform/chromium/FramelessScrollView.h"
50 #include "core/platform/chromium/FramelessScrollViewClient.h" 49 #include "core/platform/chromium/FramelessScrollViewClient.h"
51 #include "core/platform/chromium/PopupListBox.h" 50 #include "core/platform/chromium/PopupListBox.h"
52 #include "core/platform/graphics/GraphicsContext.h" 51 #include "core/platform/graphics/GraphicsContext.h"
53 #include "core/platform/graphics/IntRect.h" 52 #include "core/platform/graphics/IntRect.h"
54 53 #include <limits>
55 using namespace std;
56 54
57 namespace WebCore { 55 namespace WebCore {
58 56
59 static const int kBorderSize = 1; 57 static const int borderSize = 1;
60 58
61 static PlatformMouseEvent constructRelativeMouseEvent(const PlatformMouseEvent& e, 59 static PlatformMouseEvent constructRelativeMouseEvent(const PlatformMouseEvent& e, FramelessScrollView* parent, FramelessScrollView* child)
62 FramelessScrollView* paren t,
63 FramelessScrollView* child )
64 { 60 {
65 IntPoint pos = parent->convertSelfToChild(child, e.position()); 61 IntPoint pos = parent->convertSelfToChild(child, e.position());
66 62
67 // FIXME: This is a horrible hack since PlatformMouseEvent has no setters fo r x/y. 63 // FIXME: This is a horrible hack since PlatformMouseEvent has no setters fo r x/y.
68 PlatformMouseEvent relativeEvent = e; 64 PlatformMouseEvent relativeEvent = e;
69 IntPoint& relativePos = const_cast<IntPoint&>(relativeEvent.position()); 65 IntPoint& relativePos = const_cast<IntPoint&>(relativeEvent.position());
70 relativePos.setX(pos.x()); 66 relativePos.setX(pos.x());
71 relativePos.setY(pos.y()); 67 relativePos.setY(pos.y());
72 return relativeEvent; 68 return relativeEvent;
73 } 69 }
74 70
75 static PlatformWheelEvent constructRelativeWheelEvent(const PlatformWheelEvent& e, 71 static PlatformWheelEvent constructRelativeWheelEvent(const PlatformWheelEvent& e, FramelessScrollView* parent, FramelessScrollView* child)
76 FramelessScrollView* paren t,
77 FramelessScrollView* child )
78 { 72 {
79 IntPoint pos = parent->convertSelfToChild(child, e.position()); 73 IntPoint pos = parent->convertSelfToChild(child, e.position());
80 74
81 // FIXME: This is a horrible hack since PlatformWheelEvent has no setters fo r x/y. 75 // FIXME: This is a horrible hack since PlatformWheelEvent has no setters fo r x/y.
82 PlatformWheelEvent relativeEvent = e; 76 PlatformWheelEvent relativeEvent = e;
83 IntPoint& relativePos = const_cast<IntPoint&>(relativeEvent.position()); 77 IntPoint& relativePos = const_cast<IntPoint&>(relativeEvent.position());
84 relativePos.setX(pos.x()); 78 relativePos.setX(pos.x());
85 relativePos.setY(pos.y()); 79 relativePos.setY(pos.y());
86 return relativeEvent; 80 return relativeEvent;
87 } 81 }
88 82
89 // static 83 // static
90 PassRefPtr<PopupContainer> PopupContainer::create(PopupMenuClient* client, 84 PassRefPtr<PopupContainer> PopupContainer::create(PopupMenuClient* client, Popup Type popupType, const PopupContainerSettings& settings)
91 PopupType popupType,
92 const PopupContainerSettings& settings)
93 { 85 {
94 return adoptRef(new PopupContainer(client, popupType, settings)); 86 return adoptRef(new PopupContainer(client, popupType, settings));
95 } 87 }
96 88
97 PopupContainer::PopupContainer(PopupMenuClient* client, 89 PopupContainer::PopupContainer(PopupMenuClient* client, PopupType popupType, con st PopupContainerSettings& settings)
98 PopupType popupType,
99 const PopupContainerSettings& settings)
100 : m_listBox(PopupListBox::create(client, settings)) 90 : m_listBox(PopupListBox::create(client, settings))
101 , m_settings(settings) 91 , m_settings(settings)
102 , m_popupType(popupType) 92 , m_popupType(popupType)
103 , m_popupOpen(false) 93 , m_popupOpen(false)
104 { 94 {
105 setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff); 95 setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff);
106 } 96 }
107 97
108 PopupContainer::~PopupContainer() 98 PopupContainer::~PopupContainer()
109 { 99 {
(...skipping 15 matching lines...) Expand all
125 unsigned inverseCutoff = std::max(enclosingScreen.x() - inverseWidgetRec tInScreen.x(), 0) + std::max(inverseWidgetRectInScreen.maxX() - enclosingScreen. maxX(), 0); 115 unsigned inverseCutoff = std::max(enclosingScreen.x() - inverseWidgetRec tInScreen.x(), 0) + std::max(inverseWidgetRectInScreen.maxX() - enclosingScreen. maxX(), 0);
126 116
127 // Accept the inverse popup alignment if the trimmed content gets 117 // Accept the inverse popup alignment if the trimmed content gets
128 // shorter than that in the original alignment case. 118 // shorter than that in the original alignment case.
129 if (inverseCutoff < originalCutoff) 119 if (inverseCutoff < originalCutoff)
130 widgetRectInScreen = inverseWidgetRectInScreen; 120 widgetRectInScreen = inverseWidgetRectInScreen;
131 121
132 if (widgetRectInScreen.x() < screen.x()) { 122 if (widgetRectInScreen.x() < screen.x()) {
133 widgetRectInScreen.setWidth(widgetRectInScreen.maxX() - screen.x()); 123 widgetRectInScreen.setWidth(widgetRectInScreen.maxX() - screen.x());
134 widgetRectInScreen.setX(screen.x()); 124 widgetRectInScreen.setX(screen.x());
135 listBox->setMaxWidthAndLayout(std::max(widgetRectInScreen.width() - kBorderSize * 2, 0)); 125 listBox->setMaxWidthAndLayout(std::max(widgetRectInScreen.width() - borderSize * 2, 0));
136 } else if (widgetRectInScreen.maxX() > screen.maxX()) { 126 } else if (widgetRectInScreen.maxX() > screen.maxX()) {
137 widgetRectInScreen.setWidth(screen.maxX() - widgetRectInScreen.x()); 127 widgetRectInScreen.setWidth(screen.maxX() - widgetRectInScreen.x());
138 listBox->setMaxWidthAndLayout(std::max(widgetRectInScreen.width() - kBorderSize * 2, 0)); 128 listBox->setMaxWidthAndLayout(std::max(widgetRectInScreen.width() - borderSize * 2, 0));
139 } 129 }
140 } 130 }
141 131
142 // Calculate Y axis size. 132 // Calculate Y axis size.
143 if (widgetRectInScreen.maxY() > static_cast<int>(screen.maxY())) { 133 if (widgetRectInScreen.maxY() > static_cast<int>(screen.maxY())) {
144 if (widgetRectInScreen.y() - widgetRectInScreen.height() - targetControl Height - transformOffset.height() > 0) { 134 if (widgetRectInScreen.y() - widgetRectInScreen.height() - targetControl Height - transformOffset.height() > 0) {
145 // There is enough room to open upwards. 135 // There is enough room to open upwards.
146 widgetRectInScreen.move(-transformOffset.width(), -(widgetRectInScre en.height() + targetControlHeight + transformOffset.height())); 136 widgetRectInScreen.move(-transformOffset.width(), -(widgetRectInScre en.height() + targetControlHeight + transformOffset.height()));
147 } else { 137 } else {
148 // Figure whether upwards or downwards has more room and set the 138 // Figure whether upwards or downwards has more room and set the
149 // maximum number of items. 139 // maximum number of items.
150 int spaceAbove = widgetRectInScreen.y() - targetControlHeight + tran sformOffset.height(); 140 int spaceAbove = widgetRectInScreen.y() - targetControlHeight + tran sformOffset.height();
151 int spaceBelow = screen.maxY() - widgetRectInScreen.y(); 141 int spaceBelow = screen.maxY() - widgetRectInScreen.y();
152 if (spaceAbove > spaceBelow) 142 if (spaceAbove > spaceBelow)
153 listBox->setMaxHeight(spaceAbove); 143 listBox->setMaxHeight(spaceAbove);
154 else 144 else
155 listBox->setMaxHeight(spaceBelow); 145 listBox->setMaxHeight(spaceBelow);
156 listBox->layout(); 146 listBox->layout();
157 needToResizeView = true; 147 needToResizeView = true;
158 widgetRectInScreen.setHeight(listBox->popupContentHeight() + kBorder Size * 2); 148 widgetRectInScreen.setHeight(listBox->popupContentHeight() + borderS ize * 2);
159 // Move WebWidget upwards if necessary. 149 // Move WebWidget upwards if necessary.
160 if (spaceAbove > spaceBelow) 150 if (spaceAbove > spaceBelow)
161 widgetRectInScreen.move(-transformOffset.width(), -(widgetRectIn Screen.height() + targetControlHeight + transformOffset.height())); 151 widgetRectInScreen.move(-transformOffset.width(), -(widgetRectIn Screen.height() + targetControlHeight + transformOffset.height()));
162 } 152 }
163 } 153 }
164 return widgetRectInScreen; 154 return widgetRectInScreen;
165 } 155 }
166 156
167 IntRect PopupContainer::layoutAndCalculateWidgetRect(int targetControlHeight, co nst IntSize& transformOffset, const IntPoint& popupInitialCoordinate) 157 IntRect PopupContainer::layoutAndCalculateWidgetRect(int targetControlHeight, co nst IntSize& transformOffset, const IntPoint& popupInitialCoordinate)
168 { 158 {
169 // Reset the max width and height to their default values, they will be reco mputed below 159 // Reset the max width and height to their default values, they will be
170 // if necessary. 160 // recomputed below if necessary.
171 m_listBox->setMaxHeight(kMaxHeight); 161 m_listBox->setMaxHeight(PopupListBox::defaultMaxHeight);
172 m_listBox->setMaxWidth(std::numeric_limits<int>::max()); 162 m_listBox->setMaxWidth(std::numeric_limits<int>::max());
173 163
174 // Lay everything out to figure out our preferred size, then tell the view's 164 // Lay everything out to figure out our preferred size, then tell the view's
175 // WidgetClient about it. It should assign us a client. 165 // WidgetClient about it. It should assign us a client.
176 m_listBox->layout(); 166 m_listBox->layout();
177 fitToListBox(); 167 fitToListBox();
178 bool isRTL = this->isRTL(); 168 bool isRTL = this->isRTL();
179 169
180 // Compute the starting x-axis for a normal RTL or right-aligned LTR dropdow n. For those, 170 // Compute the starting x-axis for a normal RTL or right-aligned LTR
181 // the right edge of dropdown box should be aligned with the right edge of < select>/<input> element box, 171 // dropdown. For those, the right edge of dropdown box should be aligned
182 // and the dropdown box should be expanded to the left if more space is need ed. 172 // with the right edge of <select>/<input> element box, and the dropdown box
183 // m_originalFrameRect.width() is the width of the target <select>/<input> e lement. 173 // should be expanded to the left if more space is needed.
184 int rtlOffset = m_controlPosition.p2().x() - m_controlPosition.p1().x() - (m _listBox->width() + kBorderSize * 2); 174 // m_originalFrameRect.width() is the width of the target <select>/<input>
175 // element.
176 int rtlOffset = m_controlPosition.p2().x() - m_controlPosition.p1().x() - (m _listBox->width() + borderSize * 2);
185 int rightOffset = isRTL ? rtlOffset : 0; 177 int rightOffset = isRTL ? rtlOffset : 0;
186 178
187 // Compute the y-axis offset between the bottom left and bottom right points . 179 // Compute the y-axis offset between the bottom left and bottom right
188 // If the <select>/<input> is transformed, they are not the same. 180 // points. If the <select>/<input> is transformed, they are not the same.
189 int verticalOffset = - m_controlPosition.p4().y() + m_controlPosition.p3().y (); 181 int verticalOffset = - m_controlPosition.p4().y() + m_controlPosition.p3().y ();
190 int verticalForRTLOffset = isRTL ? verticalOffset : 0; 182 int verticalForRTLOffset = isRTL ? verticalOffset : 0;
191 183
192 // Assume m_listBox size is already calculated. 184 // Assume m_listBox size is already calculated.
193 IntSize targetSize(m_listBox->width() + kBorderSize * 2, 185 IntSize targetSize(m_listBox->width() + borderSize * 2, m_listBox->height() + borderSize * 2);
194 m_listBox->height() + kBorderSize * 2);
195 186
196 IntRect widgetRectInScreen; 187 IntRect widgetRectInScreen;
197 if (ChromeClient* client = chromeClient()) { 188 if (ChromeClient* client = chromeClient()) {
198 // If the popup would extend past the bottom of the screen, open upwards 189 // If the popup would extend past the bottom of the screen, open upwards
199 // instead. 190 // instead.
200 FloatRect screen = screenAvailableRect(m_frameView.get()); 191 FloatRect screen = screenAvailableRect(m_frameView.get());
201 // Use popupInitialCoordinate.x() + rightOffset because RTL position 192 // Use popupInitialCoordinate.x() + rightOffset because RTL position
202 // needs to be considered. 193 // needs to be considered.
203 widgetRectInScreen = client->rootViewToScreen(IntRect(popupInitialCoordi nate.x() + rightOffset, popupInitialCoordinate.y() + verticalForRTLOffset, targe tSize.width(), targetSize.height())); 194 widgetRectInScreen = client->rootViewToScreen(IntRect(popupInitialCoordi nate.x() + rightOffset, popupInitialCoordinate.y() + verticalForRTLOffset, targe tSize.width(), targetSize.height()));
204 195
205 // If we have multiple screens and the browser rect is in one screen, we have 196 // If we have multiple screens and the browser rect is in one screen, we
206 // to clip the window width to the screen width. 197 // have to clip the window width to the screen width.
207 // When clipping, we also need to set a maximum width for the list box. 198 // When clipping, we also need to set a maximum width for the list box.
208 FloatRect windowRect = client->windowRect(); 199 FloatRect windowRect = client->windowRect();
209 200
210 bool needToResizeView = false; 201 bool needToResizeView = false;
211 widgetRectInScreen = layoutAndCalculateWidgetRectInternal(widgetRectInSc reen, targetControlHeight, windowRect, screen, isRTL, rtlOffset, verticalOffset, transformOffset, m_listBox.get(), needToResizeView); 202 widgetRectInScreen = layoutAndCalculateWidgetRectInternal(widgetRectInSc reen, targetControlHeight, windowRect, screen, isRTL, rtlOffset, verticalOffset, transformOffset, m_listBox.get(), needToResizeView);
212 if (needToResizeView) 203 if (needToResizeView)
213 fitToListBox(); 204 fitToListBox();
214 } 205 }
215 206
216 return widgetRectInScreen; 207 return widgetRectInScreen;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 { 239 {
249 if (!m_popupOpen) 240 if (!m_popupOpen)
250 return; 241 return;
251 m_popupOpen = false; 242 m_popupOpen = false;
252 chromeClient()->popupClosed(this); 243 chromeClient()->popupClosed(this);
253 } 244 }
254 245
255 void PopupContainer::fitToListBox() 246 void PopupContainer::fitToListBox()
256 { 247 {
257 // Place the listbox within our border. 248 // Place the listbox within our border.
258 m_listBox->move(kBorderSize, kBorderSize); 249 m_listBox->move(borderSize, borderSize);
259 250
260 // Size ourselves to contain listbox + border. 251 // Size ourselves to contain listbox + border.
261 resize(m_listBox->width() + kBorderSize * 2, m_listBox->height() + kBorderSi ze * 2); 252 resize(m_listBox->width() + borderSize * 2, m_listBox->height() + borderSize * 2);
262 invalidate(); 253 invalidate();
263 } 254 }
264 255
265 bool PopupContainer::handleMouseDownEvent(const PlatformMouseEvent& event) 256 bool PopupContainer::handleMouseDownEvent(const PlatformMouseEvent& event)
266 { 257 {
267 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); 258 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
268 return m_listBox->handleMouseDownEvent( 259 return m_listBox->handleMouseDownEvent(
269 constructRelativeMouseEvent(event, this, m_listBox.get())); 260 constructRelativeMouseEvent(event, this, m_listBox.get()));
270 } 261 }
271 262
(...skipping 17 matching lines...) Expand all
289 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); 280 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
290 return m_listBox->handleWheelEvent( 281 return m_listBox->handleWheelEvent(
291 constructRelativeWheelEvent(event, this, m_listBox.get())); 282 constructRelativeWheelEvent(event, this, m_listBox.get()));
292 } 283 }
293 284
294 bool PopupContainer::handleTouchEvent(const PlatformTouchEvent&) 285 bool PopupContainer::handleTouchEvent(const PlatformTouchEvent&)
295 { 286 {
296 return false; 287 return false;
297 } 288 }
298 289
299 // FIXME: Refactor this code to share functionality with EventHandler::handleGes tureEvent. 290 // FIXME: Refactor this code to share functionality with
291 // EventHandler::handleGestureEvent.
300 bool PopupContainer::handleGestureEvent(const PlatformGestureEvent& gestureEvent ) 292 bool PopupContainer::handleGestureEvent(const PlatformGestureEvent& gestureEvent )
301 { 293 {
302 switch (gestureEvent.type()) { 294 switch (gestureEvent.type()) {
303 case PlatformEvent::GestureTap: { 295 case PlatformEvent::GestureTap: {
304 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.g lobalPosition(), NoButton, PlatformEvent::MouseMoved, /* clickCount */ 1, gestur eEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEvent.m etaKey(), gestureEvent.timestamp()); 296 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.g lobalPosition(), NoButton, PlatformEvent::MouseMoved, /* clickCount */ 1, gestur eEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEvent.m etaKey(), gestureEvent.timestamp());
305 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.g lobalPosition(), LeftButton, PlatformEvent::MousePressed, /* clickCount */ 1, ge stureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEve nt.metaKey(), gestureEvent.timestamp()); 297 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.g lobalPosition(), LeftButton, PlatformEvent::MousePressed, /* clickCount */ 1, ge stureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEve nt.metaKey(), gestureEvent.timestamp());
306 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.glo balPosition(), LeftButton, PlatformEvent::MouseReleased, /* clickCount */ 1, ges tureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEven t.metaKey(), gestureEvent.timestamp()); 298 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.glo balPosition(), LeftButton, PlatformEvent::MouseReleased, /* clickCount */ 1, ges tureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEven t.metaKey(), gestureEvent.timestamp());
307 // handleMouseMoveEvent(fakeMouseMove); 299 // handleMouseMoveEvent(fakeMouseMove);
308 handleMouseDownEvent(fakeMouseDown); 300 handleMouseDownEvent(fakeMouseDown);
309 handleMouseReleaseEvent(fakeMouseUp); 301 handleMouseReleaseEvent(fakeMouseUp);
(...skipping 21 matching lines...) Expand all
331 return m_listBox->handleKeyEvent(event); 323 return m_listBox->handleKeyEvent(event);
332 } 324 }
333 325
334 void PopupContainer::hide() 326 void PopupContainer::hide()
335 { 327 {
336 m_listBox->abandon(); 328 m_listBox->abandon();
337 } 329 }
338 330
339 void PopupContainer::paint(GraphicsContext* gc, const IntRect& rect) 331 void PopupContainer::paint(GraphicsContext* gc, const IntRect& rect)
340 { 332 {
341 // adjust coords for scrolled frame 333 // Adjust coords for scrolled frame.
342 IntRect r = intersection(rect, frameRect()); 334 IntRect r = intersection(rect, frameRect());
343 int tx = x(); 335 int tx = x();
344 int ty = y(); 336 int ty = y();
345 337
346 r.move(-tx, -ty); 338 r.move(-tx, -ty);
347 339
348 gc->translate(static_cast<float>(tx), static_cast<float>(ty)); 340 gc->translate(static_cast<float>(tx), static_cast<float>(ty));
349 m_listBox->paint(gc, r); 341 m_listBox->paint(gc, r);
350 gc->translate(-static_cast<float>(tx), -static_cast<float>(ty)); 342 gc->translate(-static_cast<float>(tx), -static_cast<float>(ty));
351 343
352 paintBorder(gc, rect); 344 paintBorder(gc, rect);
353 } 345 }
354 346
355 void PopupContainer::paintBorder(GraphicsContext* gc, const IntRect& rect) 347 void PopupContainer::paintBorder(GraphicsContext* gc, const IntRect& rect)
356 { 348 {
357 // FIXME: Where do we get the border color from? 349 // FIXME: Where do we get the border color from?
358 Color borderColor(127, 157, 185); 350 Color borderColor(127, 157, 185);
359 351
360 gc->setStrokeStyle(NoStroke); 352 gc->setStrokeStyle(NoStroke);
361 gc->setFillColor(borderColor, ColorSpaceDeviceRGB); 353 gc->setFillColor(borderColor, ColorSpaceDeviceRGB);
362 354
363 int tx = x(); 355 int tx = x();
364 int ty = y(); 356 int ty = y();
365 357
366 // top, left, bottom, right 358 // top, left, bottom, right
367 gc->drawRect(IntRect(tx, ty, width(), kBorderSize)); 359 gc->drawRect(IntRect(tx, ty, width(), borderSize));
368 gc->drawRect(IntRect(tx, ty, kBorderSize, height())); 360 gc->drawRect(IntRect(tx, ty, borderSize, height()));
369 gc->drawRect(IntRect(tx, ty + height() - kBorderSize, width(), kBorderSize)) ; 361 gc->drawRect(IntRect(tx, ty + height() - borderSize, width(), borderSize));
370 gc->drawRect(IntRect(tx + width() - kBorderSize, ty, kBorderSize, height())) ; 362 gc->drawRect(IntRect(tx + width() - borderSize, ty, borderSize, height()));
371 } 363 }
372 364
373 bool PopupContainer::isInterestedInEventForKey(int keyCode) 365 bool PopupContainer::isInterestedInEventForKey(int keyCode)
374 { 366 {
375 return m_listBox->isInterestedInEventForKey(keyCode); 367 return m_listBox->isInterestedInEventForKey(keyCode);
376 } 368 }
377 369
378 ChromeClient* PopupContainer::chromeClient() 370 ChromeClient* PopupContainer::chromeClient()
379 { 371 {
380 return m_frameView->frame()->page()->chrome()->client(); 372 return m_frameView->frame()->page()->chrome()->client();
381 } 373 }
382 374
383 void PopupContainer::showInRect(const FloatQuad& controlPosition, const IntSize& controlSize, FrameView* v, int index) 375 void PopupContainer::showInRect(const FloatQuad& controlPosition, const IntSize& controlSize, FrameView* v, int index)
384 { 376 {
385 // The controlSize is the size of the select box. It's usually larger than w e need. 377 // The controlSize is the size of the select box. It's usually larger than
386 // subtract border size so that usually the container will be displayed 378 // we need. Subtract border size so that usually the container will be
387 // exactly the same width as the select box. 379 // displayed exactly the same width as the select box.
388 listBox()->setBaseWidth(max(controlSize.width() - kBorderSize * 2, 0)); 380 listBox()->setBaseWidth(max(controlSize.width() - borderSize * 2, 0));
389 381
390 listBox()->updateFromElement(); 382 listBox()->updateFromElement();
391 383
392 // We set the selected item in updateFromElement(), and disregard the 384 // We set the selected item in updateFromElement(), and disregard the
393 // index passed into this function (same as Webkit's PopupMenuWin.cpp) 385 // index passed into this function (same as Webkit's PopupMenuWin.cpp)
394 // FIXME: make sure this is correct, and add an assertion. 386 // FIXME: make sure this is correct, and add an assertion.
395 // ASSERT(popupWindow(popup)->listBox()->selectedIndex() == index); 387 // ASSERT(popupWindow(popup)->listBox()->selectedIndex() == index);
396 388
397 // Save and convert the controlPosition to main window coords. 389 // Save and convert the controlPosition to main window coords.
398 m_controlPosition = controlPosition; 390 m_controlPosition = controlPosition;
399 IntPoint delta = v->contentsToWindow(IntPoint()); 391 IntPoint delta = v->contentsToWindow(IntPoint());
400 m_controlPosition.move(delta.x(), delta.y()); 392 m_controlPosition.move(delta.x(), delta.y());
401 m_controlSize = controlSize; 393 m_controlSize = controlSize;
402 394
403 // Position at (0, 0) since the frameRect().location() is relative to the pa rent WebWidget. 395 // Position at (0, 0) since the frameRect().location() is relative to the
396 // parent WebWidget.
404 setFrameRect(IntRect(IntPoint(), controlSize)); 397 setFrameRect(IntRect(IntPoint(), controlSize));
405 showPopup(v); 398 showPopup(v);
406 } 399 }
407 400
408 IntRect PopupContainer::refresh(const IntRect& targetControlRect) 401 IntRect PopupContainer::refresh(const IntRect& targetControlRect)
409 { 402 {
410 listBox()->setBaseWidth(max(m_controlSize.width() - kBorderSize * 2, 0)); 403 listBox()->setBaseWidth(max(m_controlSize.width() - borderSize * 2, 0));
411 listBox()->updateFromElement(); 404 listBox()->updateFromElement();
412 405
413 IntPoint locationInWindow = m_frameView->contentsToWindow(targetControlRect. location()); 406 IntPoint locationInWindow = m_frameView->contentsToWindow(targetControlRect. location());
414 407
415 // Move it below the select widget. 408 // Move it below the select widget.
416 locationInWindow.move(0, targetControlRect.height()); 409 locationInWindow.move(0, targetControlRect.height());
417 410
418 IntRect widgetRectInScreen = layoutAndCalculateWidgetRect(targetControlRect. height(), IntSize(), locationInWindow); 411 IntRect widgetRectInScreen = layoutAndCalculateWidgetRect(targetControlRect. height(), IntSize(), locationInWindow);
419 412
420 // Reset the size (which can be set to the PopupListBox size in layoutAndGet RTLOffset(), exceeding the available widget rectangle.) 413 // Reset the size (which can be set to the PopupListBox size in
414 // layoutAndGetRTLOffset(), exceeding the available widget rectangle.)
421 if (size() != widgetRectInScreen.size()) 415 if (size() != widgetRectInScreen.size())
422 resize(widgetRectInScreen.size()); 416 resize(widgetRectInScreen.size());
423 417
424 invalidate(); 418 invalidate();
425 419
426 return widgetRectInScreen; 420 return widgetRectInScreen;
427 } 421 }
428 422
429 inline bool PopupContainer::isRTL() const 423 inline bool PopupContainer::isRTL() const
430 { 424 {
(...skipping 21 matching lines...) Expand all
452 } 446 }
453 447
454 const WTF::Vector<PopupItem*>& PopupContainer:: popupData() const 448 const WTF::Vector<PopupItem*>& PopupContainer:: popupData() const
455 { 449 {
456 return m_listBox->items(); 450 return m_listBox->items();
457 } 451 }
458 452
459 String PopupContainer::getSelectedItemToolTip() 453 String PopupContainer::getSelectedItemToolTip()
460 { 454 {
461 // We cannot use m_popupClient->selectedIndex() to choose tooltip message, 455 // We cannot use m_popupClient->selectedIndex() to choose tooltip message,
462 // because the selectedIndex() might return final selected index, not hoveri ng selection. 456 // because the selectedIndex() might return final selected index, not
457 // hovering selection.
463 return listBox()->m_popupClient->itemToolTip(listBox()->m_selectedIndex); 458 return listBox()->m_popupClient->itemToolTip(listBox()->m_selectedIndex);
464 } 459 }
465 460
466 } // namespace WebCore 461 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/chromium/PopupContainer.h ('k') | Source/core/platform/chromium/PopupListBox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698