| 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 <X11/Xlib.h> |
| 6 #include <X11/extensions/shape.h> |
| 7 #include <stddef.h> |
| 8 |
| 9 #include <memory> |
| 5 #include <vector> | 10 #include <vector> |
| 6 | 11 |
| 7 #include <stddef.h> | |
| 8 #include <X11/extensions/shape.h> | |
| 9 #include <X11/Xlib.h> | |
| 10 | |
| 11 // Get rid of X11 macros which conflict with gtest. | 12 // Get rid of X11 macros which conflict with gtest. |
| 12 // It is necessary to include this header before the rest so that Bool can be | 13 // It is necessary to include this header before the rest so that Bool can be |
| 13 // undefined. | 14 // undefined. |
| 14 #include "ui/events/test/events_test_utils_x11.h" | 15 #include "ui/events/test/events_test_utils_x11.h" |
| 15 #undef Bool | 16 #undef Bool |
| 16 #undef None | 17 #undef None |
| 17 | 18 |
| 18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 19 #include "base/macros.h" | 20 #include "base/macros.h" |
| 20 #include "base/memory/scoped_ptr.h" | |
| 21 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
| 22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 23 #include "ui/aura/window_tree_host.h" | 23 #include "ui/aura/window_tree_host.h" |
| 24 #include "ui/base/hit_test.h" | 24 #include "ui/base/hit_test.h" |
| 25 #include "ui/base/x/x11_util.h" | 25 #include "ui/base/x/x11_util.h" |
| 26 #include "ui/events/devices/x11/touch_factory_x11.h" | 26 #include "ui/events/devices/x11/touch_factory_x11.h" |
| 27 #include "ui/events/platform/x11/x11_event_source_glib.h" | 27 #include "ui/events/platform/x11/x11_event_source_glib.h" |
| 28 #include "ui/events/test/platform_event_source_test_api.h" | 28 #include "ui/events/test/platform_event_source_test_api.h" |
| 29 #include "ui/gfx/geometry/point.h" | 29 #include "ui/gfx/geometry/point.h" |
| 30 #include "ui/gfx/geometry/rect.h" | 30 #include "ui/gfx/geometry/rect.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 std::vector<Atom> hints; | 69 std::vector<Atom> hints; |
| 70 if (ui::GetAtomArrayProperty(xwindow(), "_NET_WM_STATE", &hints)) { | 70 if (ui::GetAtomArrayProperty(xwindow(), "_NET_WM_STATE", &hints)) { |
| 71 auto it = std::find(hints.cbegin(), hints.cend(), | 71 auto it = std::find(hints.cbegin(), hints.cend(), |
| 72 atom_cache_->GetAtom(hint_)); | 72 atom_cache_->GetAtom(hint_)); |
| 73 bool hint_set = (it != hints.cend()); | 73 bool hint_set = (it != hints.cend()); |
| 74 return hint_set != wait_till_set_; | 74 return hint_set != wait_till_set_; |
| 75 } | 75 } |
| 76 return true; | 76 return true; |
| 77 } | 77 } |
| 78 | 78 |
| 79 scoped_ptr<ui::X11AtomCache> atom_cache_; | 79 std::unique_ptr<ui::X11AtomCache> atom_cache_; |
| 80 | 80 |
| 81 // The name of the hint to wait to get set or unset. | 81 // The name of the hint to wait to get set or unset. |
| 82 const char* hint_; | 82 const char* hint_; |
| 83 | 83 |
| 84 // Whether we are waiting for |hint| to be set or unset. | 84 // Whether we are waiting for |hint| to be set or unset. |
| 85 bool wait_till_set_; | 85 bool wait_till_set_; |
| 86 | 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(WMStateWaiter); | 87 DISALLOW_COPY_AND_ASSIGN(WMStateWaiter); |
| 88 }; | 88 }; |
| 89 | 89 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // WidgetDelegateView: | 133 // WidgetDelegateView: |
| 134 NonClientFrameView* CreateNonClientFrameView(Widget* widget) override { | 134 NonClientFrameView* CreateNonClientFrameView(Widget* widget) override { |
| 135 return new ShapedNonClientFrameView; | 135 return new ShapedNonClientFrameView; |
| 136 } | 136 } |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 DISALLOW_COPY_AND_ASSIGN(ShapedWidgetDelegate); | 139 DISALLOW_COPY_AND_ASSIGN(ShapedWidgetDelegate); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 // Creates a widget of size 100x100. | 142 // Creates a widget of size 100x100. |
| 143 scoped_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { | 143 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { |
| 144 scoped_ptr<Widget> widget(new Widget); | 144 std::unique_ptr<Widget> widget(new Widget); |
| 145 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 145 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
| 146 params.delegate = delegate; | 146 params.delegate = delegate; |
| 147 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 147 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 148 params.remove_standard_frame = true; | 148 params.remove_standard_frame = true; |
| 149 params.native_widget = new DesktopNativeWidgetAura(widget.get()); | 149 params.native_widget = new DesktopNativeWidgetAura(widget.get()); |
| 150 params.bounds = gfx::Rect(100, 100, 100, 100); | 150 params.bounds = gfx::Rect(100, 100, 100, 100); |
| 151 widget->Init(params); | 151 widget->Init(params); |
| 152 return widget; | 152 return widget; |
| 153 } | 153 } |
| 154 | 154 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 }; | 212 }; |
| 213 | 213 |
| 214 // Tests that the shape is properly set on the x window. | 214 // Tests that the shape is properly set on the x window. |
| 215 TEST_F(DesktopWindowTreeHostX11Test, Shape) { | 215 TEST_F(DesktopWindowTreeHostX11Test, Shape) { |
| 216 if (!ui::IsShapeExtensionAvailable()) | 216 if (!ui::IsShapeExtensionAvailable()) |
| 217 return; | 217 return; |
| 218 | 218 |
| 219 // 1) Test setting the window shape via the NonClientFrameView. This technique | 219 // 1) Test setting the window shape via the NonClientFrameView. This technique |
| 220 // is used to get rounded corners on Chrome windows when not using the native | 220 // is used to get rounded corners on Chrome windows when not using the native |
| 221 // window frame. | 221 // window frame. |
| 222 scoped_ptr<Widget> widget1 = CreateWidget(new ShapedWidgetDelegate()); | 222 std::unique_ptr<Widget> widget1 = CreateWidget(new ShapedWidgetDelegate()); |
| 223 widget1->Show(); | 223 widget1->Show(); |
| 224 ui::X11EventSource::GetInstance()->DispatchXEvents(); | 224 ui::X11EventSource::GetInstance()->DispatchXEvents(); |
| 225 | 225 |
| 226 XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); | 226 XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); |
| 227 std::vector<gfx::Rect> shape_rects = GetShapeRects(xid1); | 227 std::vector<gfx::Rect> shape_rects = GetShapeRects(xid1); |
| 228 ASSERT_FALSE(shape_rects.empty()); | 228 ASSERT_FALSE(shape_rects.empty()); |
| 229 | 229 |
| 230 // The widget was supposed to be 100x100, but the WM might have ignored this | 230 // The widget was supposed to be 100x100, but the WM might have ignored this |
| 231 // suggestion. | 231 // suggestion. |
| 232 int widget_width = widget1->GetWindowBoundsInScreen().width(); | 232 int widget_width = widget1->GetWindowBoundsInScreen().width(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 shape2.lineTo(10, 10); | 283 shape2.lineTo(10, 10); |
| 284 shape2.lineTo(0, 10); | 284 shape2.lineTo(0, 10); |
| 285 shape2.lineTo(0, 100); | 285 shape2.lineTo(0, 100); |
| 286 shape2.lineTo(100, 100); | 286 shape2.lineTo(100, 100); |
| 287 shape2.lineTo(100, 0); | 287 shape2.lineTo(100, 0); |
| 288 shape2.close(); | 288 shape2.close(); |
| 289 | 289 |
| 290 SkRegion* shape_region = new SkRegion; | 290 SkRegion* shape_region = new SkRegion; |
| 291 shape_region->setPath(shape2, SkRegion(shape2.getBounds().round())); | 291 shape_region->setPath(shape2, SkRegion(shape2.getBounds().round())); |
| 292 | 292 |
| 293 scoped_ptr<Widget> widget2(CreateWidget(NULL)); | 293 std::unique_ptr<Widget> widget2(CreateWidget(NULL)); |
| 294 widget2->Show(); | 294 widget2->Show(); |
| 295 widget2->SetShape(shape_region); | 295 widget2->SetShape(shape_region); |
| 296 ui::X11EventSource::GetInstance()->DispatchXEvents(); | 296 ui::X11EventSource::GetInstance()->DispatchXEvents(); |
| 297 | 297 |
| 298 XID xid2 = widget2->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); | 298 XID xid2 = widget2->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); |
| 299 shape_rects = GetShapeRects(xid2); | 299 shape_rects = GetShapeRects(xid2); |
| 300 ASSERT_FALSE(shape_rects.empty()); | 300 ASSERT_FALSE(shape_rects.empty()); |
| 301 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 5, 5)); | 301 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 5, 5)); |
| 302 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 15, 5)); | 302 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 15, 5)); |
| 303 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15)); | 303 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 323 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 105, 15)); | 323 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 105, 15)); |
| 324 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 500, 500)); | 324 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 500, 500)); |
| 325 } | 325 } |
| 326 | 326 |
| 327 // Test that the widget ignores changes in fullscreen state initiated by the | 327 // Test that the widget ignores changes in fullscreen state initiated by the |
| 328 // window manager (e.g. via a window manager accelerator key). | 328 // window manager (e.g. via a window manager accelerator key). |
| 329 TEST_F(DesktopWindowTreeHostX11Test, WindowManagerTogglesFullscreen) { | 329 TEST_F(DesktopWindowTreeHostX11Test, WindowManagerTogglesFullscreen) { |
| 330 if (!ui::WmSupportsHint(ui::GetAtom("_NET_WM_STATE_FULLSCREEN"))) | 330 if (!ui::WmSupportsHint(ui::GetAtom("_NET_WM_STATE_FULLSCREEN"))) |
| 331 return; | 331 return; |
| 332 | 332 |
| 333 scoped_ptr<Widget> widget = CreateWidget(new ShapedWidgetDelegate()); | 333 std::unique_ptr<Widget> widget = CreateWidget(new ShapedWidgetDelegate()); |
| 334 XID xid = widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); | 334 XID xid = widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); |
| 335 widget->Show(); | 335 widget->Show(); |
| 336 ui::X11EventSource::GetInstance()->DispatchXEvents(); | 336 ui::X11EventSource::GetInstance()->DispatchXEvents(); |
| 337 | 337 |
| 338 gfx::Rect initial_bounds = widget->GetWindowBoundsInScreen(); | 338 gfx::Rect initial_bounds = widget->GetWindowBoundsInScreen(); |
| 339 { | 339 { |
| 340 WMStateWaiter waiter(xid, "_NET_WM_STATE_FULLSCREEN", true); | 340 WMStateWaiter waiter(xid, "_NET_WM_STATE_FULLSCREEN", true); |
| 341 widget->SetFullscreen(true); | 341 widget->SetFullscreen(true); |
| 342 waiter.Wait(); | 342 waiter.Wait(); |
| 343 } | 343 } |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 EXPECT_EQ(ui::ET_MOUSEWHEEL, second_recorder.mouse_events()[0].type()); | 642 EXPECT_EQ(ui::ET_MOUSEWHEEL, second_recorder.mouse_events()[0].type()); |
| 643 EXPECT_EQ(gfx::Point(-25, -25).ToString(), | 643 EXPECT_EQ(gfx::Point(-25, -25).ToString(), |
| 644 second_recorder.mouse_events()[0].location().ToString()); | 644 second_recorder.mouse_events()[0].location().ToString()); |
| 645 | 645 |
| 646 PretendCapture(nullptr); | 646 PretendCapture(nullptr); |
| 647 first.GetNativeWindow()->RemovePreTargetHandler(&first_recorder); | 647 first.GetNativeWindow()->RemovePreTargetHandler(&first_recorder); |
| 648 second.GetNativeWindow()->RemovePreTargetHandler(&second_recorder); | 648 second.GetNativeWindow()->RemovePreTargetHandler(&second_recorder); |
| 649 } | 649 } |
| 650 | 650 |
| 651 } // namespace views | 651 } // namespace views |
| OLD | NEW |