| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <X11/extensions/shape.h> | 6 #include <X11/extensions/shape.h> |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 // Blocks till the window state hint, |hint|, is set or unset. | 47 // Blocks till the window state hint, |hint|, is set or unset. |
| 48 class WMStateWaiter : public X11PropertyChangeWaiter { | 48 class WMStateWaiter : public X11PropertyChangeWaiter { |
| 49 public: | 49 public: |
| 50 WMStateWaiter(XID window, | 50 WMStateWaiter(XID window, |
| 51 const char* hint, | 51 const char* hint, |
| 52 bool wait_till_set) | 52 bool wait_till_set) |
| 53 : X11PropertyChangeWaiter(window, "_NET_WM_STATE"), | 53 : X11PropertyChangeWaiter(window, "_NET_WM_STATE"), |
| 54 hint_(hint), | 54 hint_(hint), |
| 55 wait_till_set_(wait_till_set) { | 55 wait_till_set_(wait_till_set) { |
| 56 | 56 const char* const kAtomsToCache[] = { |
| 57 const char* kAtomsToCache[] = { | |
| 58 hint, | 57 hint, |
| 59 NULL | 58 nullptr |
| 60 }; | 59 }; |
| 61 atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomsToCache)); | 60 atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomsToCache)); |
| 62 } | 61 } |
| 63 | 62 |
| 64 ~WMStateWaiter() override {} | 63 ~WMStateWaiter() override {} |
| 65 | 64 |
| 66 private: | 65 private: |
| 67 // X11PropertyChangeWaiter: | 66 // X11PropertyChangeWaiter: |
| 68 bool ShouldKeepOnWaiting(const ui::PlatformEvent& event) override { | 67 bool ShouldKeepOnWaiting(const ui::PlatformEvent& event) override { |
| 69 std::vector<Atom> hints; | 68 std::vector<Atom> hints; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 83 | 82 |
| 84 // Whether we are waiting for |hint| to be set or unset. | 83 // Whether we are waiting for |hint| to be set or unset. |
| 85 bool wait_till_set_; | 84 bool wait_till_set_; |
| 86 | 85 |
| 87 DISALLOW_COPY_AND_ASSIGN(WMStateWaiter); | 86 DISALLOW_COPY_AND_ASSIGN(WMStateWaiter); |
| 88 }; | 87 }; |
| 89 | 88 |
| 90 // A NonClientFrameView with a window mask with the bottom right corner cut out. | 89 // A NonClientFrameView with a window mask with the bottom right corner cut out. |
| 91 class ShapedNonClientFrameView : public NonClientFrameView { | 90 class ShapedNonClientFrameView : public NonClientFrameView { |
| 92 public: | 91 public: |
| 93 explicit ShapedNonClientFrameView() { | 92 ShapedNonClientFrameView() { |
| 94 } | 93 } |
| 95 | 94 |
| 96 ~ShapedNonClientFrameView() override {} | 95 ~ShapedNonClientFrameView() override {} |
| 97 | 96 |
| 98 // NonClientFrameView: | 97 // NonClientFrameView: |
| 99 gfx::Rect GetBoundsForClientView() const override { return bounds(); } | 98 gfx::Rect GetBoundsForClientView() const override { return bounds(); } |
| 100 gfx::Rect GetWindowBoundsForClientBounds( | 99 gfx::Rect GetWindowBoundsForClientBounds( |
| 101 const gfx::Rect& client_bounds) const override { | 100 const gfx::Rect& client_bounds) const override { |
| 102 return client_bounds; | 101 return client_bounds; |
| 103 } | 102 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // 2) Test setting the window shape via Widget::SetShape(). | 279 // 2) Test setting the window shape via Widget::SetShape(). |
| 281 gfx::Path shape2; | 280 gfx::Path shape2; |
| 282 shape2.moveTo(10, 0); | 281 shape2.moveTo(10, 0); |
| 283 shape2.lineTo(10, 10); | 282 shape2.lineTo(10, 10); |
| 284 shape2.lineTo(0, 10); | 283 shape2.lineTo(0, 10); |
| 285 shape2.lineTo(0, 100); | 284 shape2.lineTo(0, 100); |
| 286 shape2.lineTo(100, 100); | 285 shape2.lineTo(100, 100); |
| 287 shape2.lineTo(100, 0); | 286 shape2.lineTo(100, 0); |
| 288 shape2.close(); | 287 shape2.close(); |
| 289 | 288 |
| 290 SkRegion* shape_region = new SkRegion; | 289 auto shape_region = base::MakeUnique<SkRegion>(); |
| 291 shape_region->setPath(shape2, SkRegion(shape2.getBounds().round())); | 290 shape_region->setPath(shape2, SkRegion(shape2.getBounds().round())); |
| 292 | 291 |
| 293 std::unique_ptr<Widget> widget2(CreateWidget(NULL)); | 292 std::unique_ptr<Widget> widget2(CreateWidget(nullptr)); |
| 294 widget2->Show(); | 293 widget2->Show(); |
| 295 widget2->SetShape(shape_region); | 294 widget2->SetShape(std::move(shape_region)); |
| 296 ui::X11EventSource::GetInstance()->DispatchXEvents(); | 295 ui::X11EventSource::GetInstance()->DispatchXEvents(); |
| 297 | 296 |
| 298 XID xid2 = widget2->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); | 297 XID xid2 = widget2->GetNativeWindow()->GetHost()->GetAcceleratedWidget(); |
| 299 shape_rects = GetShapeRects(xid2); | 298 shape_rects = GetShapeRects(xid2); |
| 300 ASSERT_FALSE(shape_rects.empty()); | 299 ASSERT_FALSE(shape_rects.empty()); |
| 301 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 5, 5)); | 300 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 5, 5)); |
| 302 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 15, 5)); | 301 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 15, 5)); |
| 303 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15)); | 302 EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15)); |
| 304 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 105, 15)); | 303 EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 105, 15)); |
| 305 | 304 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 { | 338 { |
| 340 WMStateWaiter waiter(xid, "_NET_WM_STATE_FULLSCREEN", true); | 339 WMStateWaiter waiter(xid, "_NET_WM_STATE_FULLSCREEN", true); |
| 341 widget->SetFullscreen(true); | 340 widget->SetFullscreen(true); |
| 342 waiter.Wait(); | 341 waiter.Wait(); |
| 343 } | 342 } |
| 344 EXPECT_TRUE(widget->IsFullscreen()); | 343 EXPECT_TRUE(widget->IsFullscreen()); |
| 345 | 344 |
| 346 // Emulate the window manager exiting fullscreen via a window manager | 345 // Emulate the window manager exiting fullscreen via a window manager |
| 347 // accelerator key. It should not affect the widget's fullscreen state. | 346 // accelerator key. It should not affect the widget's fullscreen state. |
| 348 { | 347 { |
| 349 const char* kAtomsToCache[] = { | 348 const char* const kAtomsToCache[] = { |
| 350 "_NET_WM_STATE", | 349 "_NET_WM_STATE", |
| 351 "_NET_WM_STATE_FULLSCREEN", | 350 "_NET_WM_STATE_FULLSCREEN", |
| 352 NULL | 351 nullptr |
| 353 }; | 352 }; |
| 354 Display* display = gfx::GetXDisplay(); | 353 Display* display = gfx::GetXDisplay(); |
| 355 ui::X11AtomCache atom_cache(display, kAtomsToCache); | 354 ui::X11AtomCache atom_cache(display, kAtomsToCache); |
| 356 | 355 |
| 357 XEvent xclient; | 356 XEvent xclient; |
| 358 memset(&xclient, 0, sizeof(xclient)); | 357 memset(&xclient, 0, sizeof(xclient)); |
| 359 xclient.type = ClientMessage; | 358 xclient.type = ClientMessage; |
| 360 xclient.xclient.window = xid; | 359 xclient.xclient.window = xid; |
| 361 xclient.xclient.message_type = atom_cache.GetAtom("_NET_WM_STATE"); | 360 xclient.xclient.message_type = atom_cache.GetAtom("_NET_WM_STATE"); |
| 362 xclient.xclient.format = 32; | 361 xclient.xclient.format = 32; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 390 params.native_widget = new DesktopNativeWidgetAura(&widget); | 389 params.native_widget = new DesktopNativeWidgetAura(&widget); |
| 391 widget.Init(params); | 390 widget.Init(params); |
| 392 widget.Show(); | 391 widget.Show(); |
| 393 ui::X11EventSource::GetInstance()->DispatchXEvents(); | 392 ui::X11EventSource::GetInstance()->DispatchXEvents(); |
| 394 | 393 |
| 395 XID xid = widget.GetNativeWindow()->GetHost()->GetAcceleratedWidget(); | 394 XID xid = widget.GetNativeWindow()->GetHost()->GetAcceleratedWidget(); |
| 396 Display* display = gfx::GetXDisplay(); | 395 Display* display = gfx::GetXDisplay(); |
| 397 | 396 |
| 398 // Minimize by sending _NET_WM_STATE_HIDDEN | 397 // Minimize by sending _NET_WM_STATE_HIDDEN |
| 399 { | 398 { |
| 400 const char* kAtomsToCache[] = { | 399 const char* const kAtomsToCache[] = { |
| 401 "_NET_WM_STATE", | 400 "_NET_WM_STATE", |
| 402 "_NET_WM_STATE_HIDDEN", | 401 "_NET_WM_STATE_HIDDEN", |
| 403 NULL | 402 nullptr |
| 404 }; | 403 }; |
| 405 | 404 |
| 406 ui::X11AtomCache atom_cache(display, kAtomsToCache); | 405 ui::X11AtomCache atom_cache(display, kAtomsToCache); |
| 407 | 406 |
| 408 std::vector< ::Atom> atom_list; | 407 std::vector< ::Atom> atom_list; |
| 409 atom_list.push_back(atom_cache.GetAtom("_NET_WM_STATE_HIDDEN")); | 408 atom_list.push_back(atom_cache.GetAtom("_NET_WM_STATE_HIDDEN")); |
| 410 ui::SetAtomArrayProperty(xid, "_NET_WM_STATE", "ATOM", atom_list); | 409 ui::SetAtomArrayProperty(xid, "_NET_WM_STATE", "ATOM", atom_list); |
| 411 | 410 |
| 412 XEvent xevent; | 411 XEvent xevent; |
| 413 memset(&xevent, 0, sizeof(xevent)); | 412 memset(&xevent, 0, sizeof(xevent)); |
| 414 xevent.type = PropertyNotify; | 413 xevent.type = PropertyNotify; |
| 415 xevent.xproperty.type = PropertyNotify; | 414 xevent.xproperty.type = PropertyNotify; |
| 416 xevent.xproperty.send_event = 1; | 415 xevent.xproperty.send_event = 1; |
| 417 xevent.xproperty.display = display; | 416 xevent.xproperty.display = display; |
| 418 xevent.xproperty.window = xid; | 417 xevent.xproperty.window = xid; |
| 419 xevent.xproperty.atom = atom_cache.GetAtom("_NET_WM_STATE"); | 418 xevent.xproperty.atom = atom_cache.GetAtom("_NET_WM_STATE"); |
| 420 xevent.xproperty.state = 0; | 419 xevent.xproperty.state = 0; |
| 421 XSendEvent(display, DefaultRootWindow(display), False, | 420 XSendEvent(display, DefaultRootWindow(display), False, |
| 422 SubstructureRedirectMask | SubstructureNotifyMask, | 421 SubstructureRedirectMask | SubstructureNotifyMask, |
| 423 &xevent); | 422 &xevent); |
| 424 | 423 |
| 425 WMStateWaiter waiter(xid, "_NET_WM_STATE_HIDDEN", true); | 424 WMStateWaiter waiter(xid, "_NET_WM_STATE_HIDDEN", true); |
| 426 waiter.Wait(); | 425 waiter.Wait(); |
| 427 } | 426 } |
| 428 EXPECT_FALSE(widget.GetNativeWindow()->IsVisible()); | 427 EXPECT_FALSE(widget.GetNativeWindow()->IsVisible()); |
| 429 | 428 |
| 430 // Show from minimized by sending _NET_WM_STATE_FOCUSED | 429 // Show from minimized by sending _NET_WM_STATE_FOCUSED |
| 431 { | 430 { |
| 432 const char* kAtomsToCache[] = { | 431 const char* const kAtomsToCache[] = { |
| 433 "_NET_WM_STATE", | 432 "_NET_WM_STATE", |
| 434 "_NET_WM_STATE_FOCUSED", | 433 "_NET_WM_STATE_FOCUSED", |
| 435 NULL | 434 nullptr |
| 436 }; | 435 }; |
| 437 | 436 |
| 438 ui::X11AtomCache atom_cache(display, kAtomsToCache); | 437 ui::X11AtomCache atom_cache(display, kAtomsToCache); |
| 439 | 438 |
| 440 std::vector< ::Atom> atom_list; | 439 std::vector< ::Atom> atom_list; |
| 441 atom_list.push_back(atom_cache.GetAtom("_NET_WM_STATE_FOCUSED")); | 440 atom_list.push_back(atom_cache.GetAtom("_NET_WM_STATE_FOCUSED")); |
| 442 ui::SetAtomArrayProperty(xid, "_NET_WM_STATE", "ATOM", atom_list); | 441 ui::SetAtomArrayProperty(xid, "_NET_WM_STATE", "ATOM", atom_list); |
| 443 | 442 |
| 444 XEvent xevent; | 443 XEvent xevent; |
| 445 memset(&xevent, 0, sizeof(xevent)); | 444 memset(&xevent, 0, sizeof(xevent)); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 EXPECT_EQ(ui::ET_MOUSEWHEEL, second_recorder.mouse_events()[0].type()); | 641 EXPECT_EQ(ui::ET_MOUSEWHEEL, second_recorder.mouse_events()[0].type()); |
| 643 EXPECT_EQ(gfx::Point(-25, -25).ToString(), | 642 EXPECT_EQ(gfx::Point(-25, -25).ToString(), |
| 644 second_recorder.mouse_events()[0].location().ToString()); | 643 second_recorder.mouse_events()[0].location().ToString()); |
| 645 | 644 |
| 646 PretendCapture(nullptr); | 645 PretendCapture(nullptr); |
| 647 first.GetNativeWindow()->RemovePreTargetHandler(&first_recorder); | 646 first.GetNativeWindow()->RemovePreTargetHandler(&first_recorder); |
| 648 second.GetNativeWindow()->RemovePreTargetHandler(&second_recorder); | 647 second.GetNativeWindow()->RemovePreTargetHandler(&second_recorder); |
| 649 } | 648 } |
| 650 | 649 |
| 651 } // namespace views | 650 } // namespace views |
| OLD | NEW |