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

Side by Side Diff: ui/views/widget/widget_interactive_uitest.cc

Issue 1876553002: mash: Close system tray bubble on click outside its bounds, part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 8 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
« ui/views/widget/root_view.h ('K') | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 event->StopPropagation(); 76 event->StopPropagation();
77 } 77 }
78 } 78 }
79 79
80 DISALLOW_COPY_AND_ASSIGN(GestureCaptureView); 80 DISALLOW_COPY_AND_ASSIGN(GestureCaptureView);
81 }; 81 };
82 82
83 // A view that always processes all mouse events. 83 // A view that always processes all mouse events.
84 class MouseView : public View { 84 class MouseView : public View {
85 public: 85 public:
86 MouseView() 86 MouseView() {}
87 : View(),
88 entered_(0),
89 exited_(0),
90 pressed_(0) {
91 }
92 ~MouseView() override {} 87 ~MouseView() override {}
93 88
94 bool OnMousePressed(const ui::MouseEvent& event) override { 89 bool OnMousePressed(const ui::MouseEvent& event) override {
95 pressed_++; 90 pressed_++;
96 return true; 91 return true;
97 } 92 }
98 93
94 void OnMouseReleased(const ui::MouseEvent& event) override { released_++; }
95
99 void OnMouseEntered(const ui::MouseEvent& event) override { entered_++; } 96 void OnMouseEntered(const ui::MouseEvent& event) override { entered_++; }
100 97
101 void OnMouseExited(const ui::MouseEvent& event) override { exited_++; } 98 void OnMouseExited(const ui::MouseEvent& event) override { exited_++; }
102 99
103 // Return the number of OnMouseEntered calls and reset the counter. 100 // Return the number of OnMouseEntered calls and reset the counter.
104 int EnteredCalls() { 101 int EnteredCalls() {
105 int i = entered_; 102 int i = entered_;
106 entered_ = 0; 103 entered_ = 0;
107 return i; 104 return i;
108 } 105 }
109 106
110 // Return the number of OnMouseExited calls and reset the counter. 107 // Return the number of OnMouseExited calls and reset the counter.
111 int ExitedCalls() { 108 int ExitedCalls() {
112 int i = exited_; 109 int i = exited_;
113 exited_ = 0; 110 exited_ = 0;
114 return i; 111 return i;
115 } 112 }
116 113
117 int pressed() const { return pressed_; } 114 int pressed() const { return pressed_; }
115 int released() const { return released_; }
118 116
119 private: 117 private:
120 int entered_; 118 int entered_ = 0;
121 int exited_; 119 int exited_ = 0;
122 120
123 int pressed_; 121 int pressed_ = 0;
122 int released_ = 0;
124 123
125 DISALLOW_COPY_AND_ASSIGN(MouseView); 124 DISALLOW_COPY_AND_ASSIGN(MouseView);
126 }; 125 };
127 126
128 // A View that shows a different widget, sets capture on that widget, and 127 // A View that shows a different widget, sets capture on that widget, and
129 // initiates a nested message-loop when it receives a mouse-press event. 128 // initiates a nested message-loop when it receives a mouse-press event.
130 class NestedLoopCaptureView : public View { 129 class NestedLoopCaptureView : public View {
131 public: 130 public:
132 explicit NestedLoopCaptureView(Widget* widget) : widget_(widget) {} 131 explicit NestedLoopCaptureView(Widget* widget) : widget_(widget) {}
133 ~NestedLoopCaptureView() override {} 132 ~NestedLoopCaptureView() override {}
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 widget1->CloseNow(); 358 widget1->CloseNow();
360 } 359 }
361 #endif // defined(OS_WIN) 360 #endif // defined(OS_WIN)
362 361
363 TEST_F(WidgetTestInteractive, CaptureAutoReset) { 362 TEST_F(WidgetTestInteractive, CaptureAutoReset) {
364 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); 363 Widget* toplevel = CreateTopLevelFramelessPlatformWidget();
365 View* container = new View; 364 View* container = new View;
366 toplevel->SetContentsView(container); 365 toplevel->SetContentsView(container);
367 366
368 EXPECT_FALSE(toplevel->HasCapture()); 367 EXPECT_FALSE(toplevel->HasCapture());
369 toplevel->SetCapture(NULL); 368 toplevel->SetCapture(nullptr);
370 EXPECT_TRUE(toplevel->HasCapture()); 369 EXPECT_TRUE(toplevel->HasCapture());
371 370
372 // By default, mouse release removes capture. 371 // By default, mouse release removes capture.
373 gfx::Point click_location(45, 15); 372 gfx::Point click_location(45, 15);
374 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, 373 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location,
375 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 374 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
376 ui::EF_LEFT_MOUSE_BUTTON); 375 ui::EF_LEFT_MOUSE_BUTTON);
377 toplevel->OnMouseEvent(&release); 376 toplevel->OnMouseEvent(&release);
378 EXPECT_FALSE(toplevel->HasCapture()); 377 EXPECT_FALSE(toplevel->HasCapture());
379 378
380 // Now a mouse release shouldn't remove capture. 379 // Now a mouse release shouldn't remove capture.
381 toplevel->set_auto_release_capture(false); 380 toplevel->set_auto_release_capture(false);
382 toplevel->SetCapture(NULL); 381 toplevel->SetCapture(nullptr);
383 EXPECT_TRUE(toplevel->HasCapture()); 382 EXPECT_TRUE(toplevel->HasCapture());
384 toplevel->OnMouseEvent(&release); 383 toplevel->OnMouseEvent(&release);
385 EXPECT_TRUE(toplevel->HasCapture()); 384 EXPECT_TRUE(toplevel->HasCapture());
386 toplevel->ReleaseCapture(); 385 toplevel->ReleaseCapture();
387 EXPECT_FALSE(toplevel->HasCapture()); 386 EXPECT_FALSE(toplevel->HasCapture());
388 387
389 toplevel->Close(); 388 toplevel->CloseNow();
390 RunPendingMessages(); 389 }
390
391 // Tests capture when auto-release is disabled and events are captured to a
392 // specific view.
393 TEST_F(WidgetTestInteractive, CaptureToViewWithoutAutoRelease) {
394 Widget* widget = CreateTopLevelFramelessPlatformWidget();
395 MouseView* target_view = new MouseView;
396 widget->SetContentsView(target_view);
397
398 // Set capture to a specific view.
399 widget->set_auto_release_capture(false);
400 widget->SetCapture(target_view);
401 EXPECT_TRUE(widget->HasCapture());
402
403 // A click is routed to the view and capture is not released on mouse release.
404 gfx::Point point(12, 34);
405 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point, point,
406 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
407 ui::EF_LEFT_MOUSE_BUTTON);
408 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point,
409 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
410 ui::EF_LEFT_MOUSE_BUTTON);
411 widget->OnMouseEvent(&press);
412 widget->OnMouseEvent(&release);
413 EXPECT_EQ(1, target_view->pressed());
414 EXPECT_EQ(1, target_view->released());
415
416 // Future events are still routed to the view.
417 widget->OnMouseEvent(&press);
418 widget->OnMouseEvent(&release);
419 EXPECT_EQ(2, target_view->pressed());
420 EXPECT_EQ(2, target_view->released());
421
422 // Capture must be explicitly released.
423 EXPECT_TRUE(widget->HasCapture());
424 widget->ReleaseCapture();
425 EXPECT_FALSE(widget->HasCapture());
426
427 widget->CloseNow();
391 } 428 }
392 429
393 TEST_F(WidgetTestInteractive, ResetCaptureOnGestureEnd) { 430 TEST_F(WidgetTestInteractive, ResetCaptureOnGestureEnd) {
394 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); 431 Widget* toplevel = CreateTopLevelFramelessPlatformWidget();
395 View* container = new View; 432 View* container = new View;
396 toplevel->SetContentsView(container); 433 toplevel->SetContentsView(container);
397 434
398 View* gesture = new GestureCaptureView; 435 View* gesture = new GestureCaptureView;
399 gesture->SetBounds(0, 0, 30, 30); 436 gesture->SetBounds(0, 0, 30, 30);
400 container->AddChildView(gesture); 437 container->AddChildView(gesture);
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 1744
1708 ui::KeyEvent key_event2(key_event); 1745 ui::KeyEvent key_event2(key_event);
1709 widget->OnKeyEvent(&key_event2); 1746 widget->OnKeyEvent(&key_event2);
1710 EXPECT_FALSE(key_event2.stopped_propagation()); 1747 EXPECT_FALSE(key_event2.stopped_propagation());
1711 1748
1712 widget->CloseNow(); 1749 widget->CloseNow();
1713 } 1750 }
1714 1751
1715 } // namespace test 1752 } // namespace test
1716 } // namespace views 1753 } // namespace views
OLDNEW
« ui/views/widget/root_view.h ('K') | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698