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

Side by Side Diff: Source/web/PopupContainerTest.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.cpp ('k') | Source/web/WebPagePopupImpl.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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 }; 69 };
70 70
71 const int screenMaxX = 1024; 71 const int screenMaxX = 1024;
72 const int screenMaxY = 768; 72 const int screenMaxY = 768;
73 const int targetControlWidth = 130; 73 const int targetControlWidth = 130;
74 74
75 static IntRect calculatePositionWithTransformAndRTL(const IntRect& initialRect, const IntSize& transformOffset, int verticalOffset, PopupContent* content) 75 static IntRect calculatePositionWithTransformAndRTL(const IntRect& initialRect, const IntSize& transformOffset, int verticalOffset, PopupContent* content)
76 { 76 {
77 const bool isRTL = true; 77 const bool isRTL = true;
78 const int targetControlHeight = 20; 78 const int targetControlHeight = 20;
79 const FloatRect screenRect(0, 0, screenMaxX, screenMaxY); 79 const IntRect screenRect(0, 0, screenMaxX, screenMaxY);
80 const FloatRect windowRect(0, 0, 512, 512); 80 const IntRect windowRect(0, 0, 512, 512);
81 int rtlOffset = targetControlWidth - initialRect.width(); 81 int rtlOffset = targetControlWidth - initialRect.width();
82 bool needToResizeView = false; 82 bool needToResizeView = false;
83 return PopupContainer::layoutAndCalculateWidgetRectInternal(initialRect, tar getControlHeight, windowRect, screenRect, !isRTL, rtlOffset, verticalOffset, tra nsformOffset, content, needToResizeView); 83 return PopupContainer::layoutAndCalculateWidgetRectInternal(initialRect, tar getControlHeight, windowRect, screenRect, !isRTL, rtlOffset, verticalOffset, tra nsformOffset, content, needToResizeView);
84 } 84 }
85 85
86 static IntRect calculatePosition(const IntRect& initialRect, PopupContent* conte nt, FloatRect windowRect = FloatRect(0, 0, 512, 512), bool isRTL = true) 86 static IntRect calculatePosition(const IntRect& initialRect, PopupContent* conte nt, IntRect windowRect = IntRect(0, 0, 512, 512), bool isRTL = true)
87 { 87 {
88 const int targetControlHeight = 20; 88 const int targetControlHeight = 20;
89 const FloatRect screenRect(0, 0, screenMaxX, screenMaxY); 89 const IntRect screenRect(0, 0, screenMaxX, screenMaxY);
90 int rtlOffset = (targetControlWidth - initialRect.width()) * (isRTL ? 1 : -1 ); 90 int rtlOffset = (targetControlWidth - initialRect.width()) * (isRTL ? 1 : -1 );
91 bool needToResizeView = false; 91 bool needToResizeView = false;
92 return PopupContainer::layoutAndCalculateWidgetRectInternal(initialRect, tar getControlHeight, windowRect, screenRect, !isRTL, rtlOffset, 0, IntSize(), conte nt, needToResizeView); 92 return PopupContainer::layoutAndCalculateWidgetRectInternal(initialRect, tar getControlHeight, windowRect, screenRect, !isRTL, rtlOffset, 0, IntSize(), conte nt, needToResizeView);
93 } 93 }
94 94
95 TEST(PopupContainerTest, PopupPosition) 95 TEST(PopupContainerTest, PopupPosition)
96 { 96 {
97 // Suppose that initialRect.location is the bottom-left corner of the target 97 // Suppose that initialRect.location is the bottom-left corner of the target
98 // control such as <select>. 98 // control such as <select>.
99 99
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 IntRect resultRect = calculatePosition(initialRect, &content); 163 IntRect resultRect = calculatePosition(initialRect, &content);
164 EXPECT_EQ(IntRect(100, 10, targetControlWidth, 370), resultRect); 164 EXPECT_EQ(IntRect(100, 10, targetControlWidth, 370), resultRect);
165 EXPECT_TRUE(content.layoutCount); 165 EXPECT_TRUE(content.layoutCount);
166 EXPECT_EQ(368, content.height); 166 EXPECT_EQ(368, content.height);
167 } 167 }
168 168
169 { 169 {
170 // There is not enough room to the right, so open the popup menu to the left. 170 // There is not enough room to the right, so open the popup menu to the left.
171 IntRect initialRect(screenMaxX - targetControlWidth - 6, 100, targetCont rolWidth * 2, 100); 171 IntRect initialRect(screenMaxX - targetControlWidth - 6, 100, targetCont rolWidth * 2, 100);
172 MockPopupContent content(initialRect.size()); 172 MockPopupContent content(initialRect.size());
173 IntRect resultRect = calculatePosition(initialRect, &content, FloatRect( 0, 0, screenMaxX, screenMaxY), false); 173 IntRect resultRect = calculatePosition(initialRect, &content, IntRect(0, 0, screenMaxX, screenMaxY), false);
174 EXPECT_EQ(IntRect(758, 100, 260, 100), resultRect); 174 EXPECT_EQ(IntRect(758, 100, 260, 100), resultRect);
175 } 175 }
176 176
177 { 177 {
178 // Test for transform:rotate(53deg). 178 // Test for transform:rotate(53deg).
179 IntRect initialRect(100, 700, targetControlWidth, 258); 179 IntRect initialRect(100, 700, targetControlWidth, 258);
180 MockPopupContent content(initialRect.size()); 180 MockPopupContent content(initialRect.size());
181 IntSize transformOffset(-4, -8); 181 IntSize transformOffset(-4, -8);
182 IntRect resultRect = calculatePositionWithTransformAndRTL(initialRect, t ransformOffset, -104, &content); 182 IntRect resultRect = calculatePositionWithTransformAndRTL(initialRect, t ransformOffset, -104, &content);
183 EXPECT_EQ(IntRect(104, 430, targetControlWidth, 258), resultRect); 183 EXPECT_EQ(IntRect(104, 430, targetControlWidth, 258), resultRect);
184 EXPECT_EQ(0u, content.layoutCount); 184 EXPECT_EQ(0u, content.layoutCount);
185 } 185 }
186 186
187 { 187 {
188 // Test for transform:rotate(-53deg). 188 // Test for transform:rotate(-53deg).
189 IntRect initialRect(100, 700, targetControlWidth, 258); 189 IntRect initialRect(100, 700, targetControlWidth, 258);
190 MockPopupContent content(initialRect.size()); 190 MockPopupContent content(initialRect.size());
191 IntSize transformOffset(4, -8); 191 IntSize transformOffset(4, -8);
192 IntRect resultRect = calculatePositionWithTransformAndRTL(initialRect, t ransformOffset, 104, &content); 192 IntRect resultRect = calculatePositionWithTransformAndRTL(initialRect, t ransformOffset, 104, &content);
193 EXPECT_EQ(IntRect(96, 430, targetControlWidth, 258), resultRect); 193 EXPECT_EQ(IntRect(96, 430, targetControlWidth, 258), resultRect);
194 EXPECT_EQ(0u, content.layoutCount); 194 EXPECT_EQ(0u, content.layoutCount);
195 } 195 }
196 } 196 }
OLDNEW
« no previous file with comments | « Source/web/PopupContainer.cpp ('k') | Source/web/WebPagePopupImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698