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

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

Issue 879913003: Use IntRect instead of FloatRect for window positions and sizes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: added FIXME comments Created 5 years, 10 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
« no previous file with comments | « Source/web/PopupContainer.h ('k') | Source/web/PopupContainerTest.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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 #endif 105 #endif
106 } 106 }
107 107
108 void PopupContainer::trace(Visitor* visitor) 108 void PopupContainer::trace(Visitor* visitor)
109 { 109 {
110 visitor->trace(m_frameView); 110 visitor->trace(m_frameView);
111 visitor->trace(m_listBox); 111 visitor->trace(m_listBox);
112 Widget::trace(visitor); 112 Widget::trace(visitor);
113 } 113 }
114 114
115 IntRect PopupContainer::layoutAndCalculateWidgetRectInternal(IntRect widgetRectI nScreen, int targetControlHeight, const FloatRect& windowRect, const FloatRect& screen, bool isRTL, const int rtlOffset, const int verticalOffset, const IntSize & transformOffset, PopupContent* listBox, bool& needToResizeView) 115 IntRect PopupContainer::layoutAndCalculateWidgetRectInternal(IntRect widgetRectI nScreen, int targetControlHeight, const IntRect& windowRect, const IntRect& scre en, bool isRTL, const int rtlOffset, const int verticalOffset, const IntSize& tr ansformOffset, PopupContent* listBox, bool& needToResizeView)
116 { 116 {
117 ASSERT(listBox); 117 ASSERT(listBox);
118 if (windowRect.x() >= screen.x() && windowRect.maxX() <= screen.maxX() && (w idgetRectInScreen.x() < screen.x() || widgetRectInScreen.maxX() > screen.maxX()) ) { 118 if (windowRect.x() >= screen.x() && windowRect.maxX() <= screen.maxX() && (w idgetRectInScreen.x() < screen.x() || widgetRectInScreen.maxX() > screen.maxX()) ) {
119 // First, inverse the popup alignment if it does not fit the screen - 119 // First, inverse the popup alignment if it does not fit the screen -
120 // this might fix things (or make them better). 120 // this might fix things (or make them better).
121 IntRect inverseWidgetRectInScreen = widgetRectInScreen; 121 IntRect inverseWidgetRectInScreen = widgetRectInScreen;
122 inverseWidgetRectInScreen.setX(inverseWidgetRectInScreen.x() + (isRTL ? -rtlOffset : rtlOffset)); 122 inverseWidgetRectInScreen.setX(inverseWidgetRectInScreen.x() + (isRTL ? -rtlOffset : rtlOffset));
123 inverseWidgetRectInScreen.setY(inverseWidgetRectInScreen.y() + (isRTL ? -verticalOffset : verticalOffset)); 123 inverseWidgetRectInScreen.setY(inverseWidgetRectInScreen.y() + (isRTL ? -verticalOffset : verticalOffset));
124 IntRect enclosingScreen = enclosingIntRect(screen); 124 unsigned originalCutoff = std::max(screen.x() - widgetRectInScreen.x(), 0) + std::max(widgetRectInScreen.maxX() - screen.maxX(), 0);
125 unsigned originalCutoff = std::max(enclosingScreen.x() - widgetRectInScr een.x(), 0) + std::max(widgetRectInScreen.maxX() - enclosingScreen.maxX(), 0); 125 unsigned inverseCutoff = std::max(screen.x() - inverseWidgetRectInScreen .x(), 0) + std::max(inverseWidgetRectInScreen.maxX() - screen.maxX(), 0);
126 unsigned inverseCutoff = std::max(enclosingScreen.x() - inverseWidgetRec tInScreen.x(), 0) + std::max(inverseWidgetRectInScreen.maxX() - enclosingScreen. maxX(), 0);
127 126
128 // Accept the inverse popup alignment if the trimmed content gets 127 // Accept the inverse popup alignment if the trimmed content gets
129 // shorter than that in the original alignment case. 128 // shorter than that in the original alignment case.
130 if (inverseCutoff < originalCutoff) 129 if (inverseCutoff < originalCutoff)
131 widgetRectInScreen = inverseWidgetRectInScreen; 130 widgetRectInScreen = inverseWidgetRectInScreen;
132 131
133 if (widgetRectInScreen.x() < screen.x()) { 132 if (widgetRectInScreen.x() < screen.x()) {
134 widgetRectInScreen.setWidth(widgetRectInScreen.maxX() - screen.x()); 133 widgetRectInScreen.setWidth(widgetRectInScreen.maxX() - screen.x());
135 widgetRectInScreen.setX(screen.x()); 134 widgetRectInScreen.setX(screen.x());
136 listBox->setMaxWidthAndLayout(std::max(widgetRectInScreen.width() - borderSize * 2, 0)); 135 listBox->setMaxWidthAndLayout(std::max(widgetRectInScreen.width() - borderSize * 2, 0));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // points. If the <select>/<input> is transformed, they are not the same. 190 // points. If the <select>/<input> is transformed, they are not the same.
192 int verticalOffset = - m_controlPosition.p4().y() + m_controlPosition.p3().y (); 191 int verticalOffset = - m_controlPosition.p4().y() + m_controlPosition.p3().y ();
193 int verticalForRTLOffset = isRTL ? verticalOffset : 0; 192 int verticalForRTLOffset = isRTL ? verticalOffset : 0;
194 193
195 // Assume m_listBox size is already calculated. 194 // Assume m_listBox size is already calculated.
196 IntSize targetSize(m_listBox->width() + borderSize * 2, m_listBox->height() + borderSize * 2); 195 IntSize targetSize(m_listBox->width() + borderSize * 2, m_listBox->height() + borderSize * 2);
197 196
198 IntRect widgetRectInScreen; 197 IntRect widgetRectInScreen;
199 // If the popup would extend past the bottom of the screen, open upwards 198 // If the popup would extend past the bottom of the screen, open upwards
200 // instead. 199 // instead.
201 FloatRect screen = screenAvailableRect(m_frameView.get()); 200 IntRect screen = screenAvailableRect(m_frameView.get());
202 // Use popupInitialCoordinate.x() + rightOffset because RTL position 201 // Use popupInitialCoordinate.x() + rightOffset because RTL position
203 // needs to be considered. 202 // needs to be considered.
204 float pageScaleFactor = m_frameView->frame().page()->pageScaleFactor(); 203 float pageScaleFactor = m_frameView->frame().page()->pageScaleFactor();
205 int popupX = round((popupInitialCoordinate.x() + rightOffset) * pageScaleFac tor); 204 int popupX = round((popupInitialCoordinate.x() + rightOffset) * pageScaleFac tor);
206 int popupY = round((popupInitialCoordinate.y() + verticalForRTLOffset) * pag eScaleFactor); 205 int popupY = round((popupInitialCoordinate.y() + verticalForRTLOffset) * pag eScaleFactor);
207 widgetRectInScreen = chromeClient().rootViewToScreen(IntRect(popupX, popupY, targetSize.width(), targetSize.height())); 206 widgetRectInScreen = chromeClient().rootViewToScreen(IntRect(popupX, popupY, targetSize.width(), targetSize.height()));
208 207
209 // If we have multiple screens and the browser rect is in one screen, we 208 // If we have multiple screens and the browser rect is in one screen, we
210 // have to clip the window width to the screen width. 209 // have to clip the window width to the screen width.
211 // When clipping, we also need to set a maximum width for the list box. 210 // When clipping, we also need to set a maximum width for the list box.
212 FloatRect windowRect = chromeClient().windowRect(); 211 IntRect windowRect = chromeClient().windowRect();
213 212
214 bool needToResizeView = false; 213 bool needToResizeView = false;
215 widgetRectInScreen = layoutAndCalculateWidgetRectInternal(widgetRectInScreen , targetControlHeight, windowRect, screen, isRTL, rtlOffset, verticalOffset, tra nsformOffset, m_listBox.get(), needToResizeView); 214 widgetRectInScreen = layoutAndCalculateWidgetRectInternal(widgetRectInScreen , targetControlHeight, windowRect, screen, isRTL, rtlOffset, verticalOffset, tra nsformOffset, m_listBox.get(), needToResizeView);
216 if (needToResizeView) 215 if (needToResizeView)
217 fitToListBox(); 216 fitToListBox();
218 217
219 return widgetRectInScreen; 218 return widgetRectInScreen;
220 } 219 }
221 220
222 void PopupContainer::showPopup(FrameView* view) 221 void PopupContainer::showPopup(FrameView* view)
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 } 557 }
559 558
560 IntPoint PopupContainer::convertSelfToChild(const Widget* child, const IntPoint& point) const 559 IntPoint PopupContainer::convertSelfToChild(const Widget* child, const IntPoint& point) const
561 { 560 {
562 IntPoint newPoint = point; 561 IntPoint newPoint = point;
563 newPoint.moveBy(-child->location()); 562 newPoint.moveBy(-child->location());
564 return newPoint; 563 return newPoint;
565 } 564 }
566 565
567 } // namespace blink 566 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/PopupContainer.h ('k') | Source/web/PopupContainerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698