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

Side by Side Diff: Source/web/PopupContainer.cpp

Issue 22955006: Chrome::client() should return a ChromeClient reference. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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
« no previous file with comments | « Source/web/PopupContainer.h ('k') | Source/web/StorageNamespaceProxy.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 // Compute the y-axis offset between the bottom left and bottom right 179 // Compute the y-axis offset between the bottom left and bottom right
180 // points. If the <select>/<input> is transformed, they are not the same. 180 // points. If the <select>/<input> is transformed, they are not the same.
181 int verticalOffset = - m_controlPosition.p4().y() + m_controlPosition.p3().y (); 181 int verticalOffset = - m_controlPosition.p4().y() + m_controlPosition.p3().y ();
182 int verticalForRTLOffset = isRTL ? verticalOffset : 0; 182 int verticalForRTLOffset = isRTL ? verticalOffset : 0;
183 183
184 // Assume m_listBox size is already calculated. 184 // Assume m_listBox size is already calculated.
185 IntSize targetSize(m_listBox->width() + borderSize * 2, m_listBox->height() + borderSize * 2); 185 IntSize targetSize(m_listBox->width() + borderSize * 2, m_listBox->height() + borderSize * 2);
186 186
187 IntRect widgetRectInScreen; 187 IntRect widgetRectInScreen;
188 if (ChromeClient* client = chromeClient()) { 188 // 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 189 // instead.
190 // instead. 190 FloatRect screen = screenAvailableRect(m_frameView.get());
191 FloatRect screen = screenAvailableRect(m_frameView.get()); 191 // Use popupInitialCoordinate.x() + rightOffset because RTL position
192 // Use popupInitialCoordinate.x() + rightOffset because RTL position 192 // needs to be considered.
193 // needs to be considered. 193 widgetRectInScreen = chromeClient().rootViewToScreen(IntRect(popupInitialCoo rdinate.x() + rightOffset, popupInitialCoordinate.y() + verticalForRTLOffset, ta rgetSize.width(), targetSize.height()));
194 widgetRectInScreen = client->rootViewToScreen(IntRect(popupInitialCoordi nate.x() + rightOffset, popupInitialCoordinate.y() + verticalForRTLOffset, targe tSize.width(), targetSize.height()));
195 194
196 // If we have multiple screens and the browser rect is in one screen, we 195 // If we have multiple screens and the browser rect is in one screen, we
197 // have to clip the window width to the screen width. 196 // have to clip the window width to the screen width.
198 // When clipping, we also need to set a maximum width for the list box. 197 // When clipping, we also need to set a maximum width for the list box.
199 FloatRect windowRect = client->windowRect(); 198 FloatRect windowRect = chromeClient().windowRect();
200 199
201 bool needToResizeView = false; 200 bool needToResizeView = false;
202 widgetRectInScreen = layoutAndCalculateWidgetRectInternal(widgetRectInSc reen, targetControlHeight, windowRect, screen, isRTL, rtlOffset, verticalOffset, transformOffset, m_listBox.get(), needToResizeView); 201 widgetRectInScreen = layoutAndCalculateWidgetRectInternal(widgetRectInScreen , targetControlHeight, windowRect, screen, isRTL, rtlOffset, verticalOffset, tra nsformOffset, m_listBox.get(), needToResizeView);
203 if (needToResizeView) 202 if (needToResizeView)
204 fitToListBox(); 203 fitToListBox();
205 }
206 204
207 return widgetRectInScreen; 205 return widgetRectInScreen;
208 } 206 }
209 207
210 void PopupContainer::showPopup(FrameView* view) 208 void PopupContainer::showPopup(FrameView* view)
211 { 209 {
212 m_frameView = view; 210 m_frameView = view;
213 listBox()->m_focusedElement = m_frameView->frame()->document()->focusedEleme nt(); 211 listBox()->m_focusedElement = m_frameView->frame()->document()->focusedEleme nt();
214 212
215 if (ChromeClient* client = chromeClient()) { 213 IntSize transformOffset(m_controlPosition.p4().x() - m_controlPosition.p1(). x(), m_controlPosition.p4().y() - m_controlPosition.p1().y() - m_controlSize.hei ght());
216 IntSize transformOffset(m_controlPosition.p4().x() - m_controlPosition.p 1().x(), m_controlPosition.p4().y() - m_controlPosition.p1().y() - m_controlSize .height()); 214 chromeClient().popupOpened(this, layoutAndCalculateWidgetRect(m_controlSize. height(), transformOffset, roundedIntPoint(m_controlPosition.p4())), false);
217 client->popupOpened(this, layoutAndCalculateWidgetRect(m_controlSize.hei ght(), transformOffset, roundedIntPoint(m_controlPosition.p4())), false); 215 m_popupOpen = true;
218 m_popupOpen = true;
219 }
220 216
221 if (!m_listBox->parent()) 217 if (!m_listBox->parent())
222 addChild(m_listBox.get()); 218 addChild(m_listBox.get());
223 219
224 // Enable scrollbars after the listbox is inserted into the hierarchy, 220 // Enable scrollbars after the listbox is inserted into the hierarchy,
225 // so it has a proper WidgetClient. 221 // so it has a proper WidgetClient.
226 m_listBox->setVerticalScrollbarMode(ScrollbarAuto); 222 m_listBox->setVerticalScrollbarMode(ScrollbarAuto);
227 223
228 m_listBox->scrollToRevealSelection(); 224 m_listBox->scrollToRevealSelection();
229 225
230 invalidate(); 226 invalidate();
231 } 227 }
232 228
233 void PopupContainer::hidePopup() 229 void PopupContainer::hidePopup()
234 { 230 {
235 listBox()->hidePopup(); 231 listBox()->hidePopup();
236 } 232 }
237 233
238 void PopupContainer::notifyPopupHidden() 234 void PopupContainer::notifyPopupHidden()
239 { 235 {
240 if (!m_popupOpen) 236 if (!m_popupOpen)
241 return; 237 return;
242 m_popupOpen = false; 238 m_popupOpen = false;
243 chromeClient()->popupClosed(this); 239 chromeClient().popupClosed(this);
244 } 240 }
245 241
246 void PopupContainer::fitToListBox() 242 void PopupContainer::fitToListBox()
247 { 243 {
248 // Place the listbox within our border. 244 // Place the listbox within our border.
249 m_listBox->move(borderSize, borderSize); 245 m_listBox->move(borderSize, borderSize);
250 246
251 // Size ourselves to contain listbox + border. 247 // Size ourselves to contain listbox + border.
252 resize(m_listBox->width() + borderSize * 2, m_listBox->height() + borderSize * 2); 248 resize(m_listBox->width() + borderSize * 2, m_listBox->height() + borderSize * 2);
253 invalidate(); 249 invalidate();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 gc->drawRect(IntRect(tx, ty, borderSize, height())); 356 gc->drawRect(IntRect(tx, ty, borderSize, height()));
361 gc->drawRect(IntRect(tx, ty + height() - borderSize, width(), borderSize)); 357 gc->drawRect(IntRect(tx, ty + height() - borderSize, width(), borderSize));
362 gc->drawRect(IntRect(tx + width() - borderSize, ty, borderSize, height())); 358 gc->drawRect(IntRect(tx + width() - borderSize, ty, borderSize, height()));
363 } 359 }
364 360
365 bool PopupContainer::isInterestedInEventForKey(int keyCode) 361 bool PopupContainer::isInterestedInEventForKey(int keyCode)
366 { 362 {
367 return m_listBox->isInterestedInEventForKey(keyCode); 363 return m_listBox->isInterestedInEventForKey(keyCode);
368 } 364 }
369 365
370 ChromeClient* PopupContainer::chromeClient() 366 ChromeClient& PopupContainer::chromeClient()
371 { 367 {
372 return m_frameView->frame()->page()->chrome().client(); 368 return m_frameView->frame()->page()->chrome().client();
373 } 369 }
374 370
375 void PopupContainer::showInRect(const FloatQuad& controlPosition, const IntSize& controlSize, FrameView* v, int index) 371 void PopupContainer::showInRect(const FloatQuad& controlPosition, const IntSize& controlSize, FrameView* v, int index)
376 { 372 {
377 // The controlSize is the size of the select box. It's usually larger than 373 // The controlSize is the size of the select box. It's usually larger than
378 // we need. Subtract border size so that usually the container will be 374 // we need. Subtract border size so that usually the container will be
379 // displayed exactly the same width as the select box. 375 // displayed exactly the same width as the select box.
380 listBox()->setBaseWidth(max(controlSize.width() - borderSize * 2, 0)); 376 listBox()->setBaseWidth(max(controlSize.width() - borderSize * 2, 0));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 452
457 String PopupContainer::getSelectedItemToolTip() 453 String PopupContainer::getSelectedItemToolTip()
458 { 454 {
459 // We cannot use m_popupClient->selectedIndex() to choose tooltip message, 455 // We cannot use m_popupClient->selectedIndex() to choose tooltip message,
460 // because the selectedIndex() might return final selected index, not 456 // because the selectedIndex() might return final selected index, not
461 // hovering selection. 457 // hovering selection.
462 return listBox()->m_popupClient->itemToolTip(listBox()->m_selectedIndex); 458 return listBox()->m_popupClient->itemToolTip(listBox()->m_selectedIndex);
463 } 459 }
464 460
465 } // namespace WebCore 461 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/web/PopupContainer.h ('k') | Source/web/StorageNamespaceProxy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698