| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include <X11/extensions/shape.h> | 7 #include <X11/extensions/shape.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 | 9 |
| 10 // Get rid of X11 macros which conflict with gtest. | 10 // Get rid of X11 macros which conflict with gtest. |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // 1) Test setting the window shape via the NonClientFrameView. This technique | 255 // 1) Test setting the window shape via the NonClientFrameView. This technique |
| 256 // is used to get rounded corners on Chrome windows when not using the native | 256 // is used to get rounded corners on Chrome windows when not using the native |
| 257 // window frame. | 257 // window frame. |
| 258 scoped_ptr<Widget> widget1 = CreateWidget(new ShapedWidgetDelegate()); | 258 scoped_ptr<Widget> widget1 = CreateWidget(new ShapedWidgetDelegate()); |
| 259 widget1->Show(); | 259 widget1->Show(); |
| 260 ui::X11EventSource::GetInstance()->DispatchXEvents(); | 260 ui::X11EventSource::GetInstance()->DispatchXEvents(); |
| 261 | 261 |
| 262 XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); | 262 XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); |
| 263 std::vector<gfx::Rect> shape_rects = GetShapeRects(xid1); | 263 std::vector<gfx::Rect> shape_rects = GetShapeRects(xid1); |
| 264 ASSERT_FALSE(shape_rects.empty()); | 264 ASSERT_FALSE(shape_rects.empty()); |
| 265 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 85, 5)); | 265 |
| 266 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 95, 5)); | 266 // The widget was supposed to be 100x100, but the WM might have ignored this |
| 267 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15)); | 267 // suggestion. |
| 268 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 105, 15)); | 268 int widget_width = widget1->GetWindowBoundsInScreen().width(); |
| 269 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, widget_width - 15, 5)); |
| 270 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, widget_width - 5, 5)); |
| 271 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, widget_width - 5, 15)); |
| 272 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, widget_width + 5, 15)); |
| 269 | 273 |
| 270 // Changing widget's size should update the shape. | 274 // Changing widget's size should update the shape. |
| 271 widget1->SetBounds(gfx::Rect(100, 100, 200, 200)); | 275 widget1->SetBounds(gfx::Rect(100, 100, 200, 200)); |
| 272 ui::X11EventSource::GetInstance()->DispatchXEvents(); | 276 ui::X11EventSource::GetInstance()->DispatchXEvents(); |
| 273 | 277 |
| 274 shape_rects = GetShapeRects(xid1); | 278 if (widget1->GetWindowBoundsInScreen().width() == 200) { |
| 275 ASSERT_FALSE(shape_rects.empty()); | 279 shape_rects = GetShapeRects(xid1); |
| 276 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 85, 5)); | 280 ASSERT_FALSE(shape_rects.empty()); |
| 277 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 5)); | 281 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 85, 5)); |
| 278 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 185, 5)); | 282 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 5)); |
| 279 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 195, 5)); | 283 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 185, 5)); |
| 280 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 195, 15)); | 284 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 195, 5)); |
| 281 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 205, 15)); | 285 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 195, 15)); |
| 282 | 286 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 205, 15)); |
| 283 // The shape should be changed to a rectangle which fills the entire screen | |
| 284 // when |widget1| is maximized. | |
| 285 { | |
| 286 MaximizeWaiter waiter(xid1); | |
| 287 widget1->Maximize(); | |
| 288 waiter.Wait(); | |
| 289 } | 287 } |
| 290 | 288 |
| 291 // xvfb does not support Xrandr so we cannot check the maximized window's | 289 if (ui::WmSupportsHint(ui::GetAtom("_NET_WM_STATE_MAXIMIZED_VERT"))) { |
| 292 // bounds. | 290 // The shape should be changed to a rectangle which fills the entire screen |
| 293 gfx::Rect maximized_bounds; | 291 // when |widget1| is maximized. |
| 294 ui::GetWindowRect(xid1, &maximized_bounds); | 292 { |
| 293 MaximizeWaiter waiter(xid1); |
| 294 widget1->Maximize(); |
| 295 waiter.Wait(); |
| 296 } |
| 295 | 297 |
| 296 shape_rects = GetShapeRects(xid1); | 298 // xvfb does not support Xrandr so we cannot check the maximized window's |
| 297 ASSERT_FALSE(shape_rects.empty()); | 299 // bounds. |
| 298 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, | 300 gfx::Rect maximized_bounds; |
| 299 maximized_bounds.width() - 1, | 301 ui::GetWindowRect(xid1, &maximized_bounds); |
| 300 5)); | 302 |
| 301 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, | 303 shape_rects = GetShapeRects(xid1); |
| 302 maximized_bounds.width() - 1, | 304 ASSERT_FALSE(shape_rects.empty()); |
| 303 15)); | 305 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, |
| 306 maximized_bounds.width() - 1, |
| 307 5)); |
| 308 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, |
| 309 maximized_bounds.width() - 1, |
| 310 15)); |
| 311 } |
| 304 | 312 |
| 305 // 2) Test setting the window shape via Widget::SetShape(). | 313 // 2) Test setting the window shape via Widget::SetShape(). |
| 306 gfx::Path shape2; | 314 gfx::Path shape2; |
| 307 shape2.moveTo(10, 0); | 315 shape2.moveTo(10, 0); |
| 308 shape2.lineTo(10, 10); | 316 shape2.lineTo(10, 10); |
| 309 shape2.lineTo(0, 10); | 317 shape2.lineTo(0, 10); |
| 310 shape2.lineTo(0, 100); | 318 shape2.lineTo(0, 100); |
| 311 shape2.lineTo(100, 100); | 319 shape2.lineTo(100, 100); |
| 312 shape2.lineTo(100, 0); | 320 shape2.lineTo(100, 0); |
| 313 shape2.close(); | 321 shape2.close(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 329 widget2->SetBounds(gfx::Rect(100, 100, 200, 200)); | 337 widget2->SetBounds(gfx::Rect(100, 100, 200, 200)); |
| 330 shape_rects = GetShapeRects(xid2); | 338 shape_rects = GetShapeRects(xid2); |
| 331 ASSERT_FALSE(shape_rects.empty()); | 339 ASSERT_FALSE(shape_rects.empty()); |
| 332 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 5, 5)); | 340 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 5, 5)); |
| 333 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 15, 5)); | 341 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 15, 5)); |
| 334 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15)); | 342 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15)); |
| 335 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 105, 15)); | 343 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 105, 15)); |
| 336 } | 344 } |
| 337 | 345 |
| 338 } // namespace views | 346 } // namespace views |
| OLD | NEW |