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 #import "ui/views/widget/native_widget_mac.h" | 5 #import "ui/views/widget/native_widget_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #import "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 // BubbleDialogDelegateView. | 253 // BubbleDialogDelegateView. |
254 class SimpleBubbleView : public BubbleDialogDelegateView { | 254 class SimpleBubbleView : public BubbleDialogDelegateView { |
255 public: | 255 public: |
256 SimpleBubbleView() {} | 256 SimpleBubbleView() {} |
257 ~SimpleBubbleView() override {} | 257 ~SimpleBubbleView() override {} |
258 | 258 |
259 private: | 259 private: |
260 DISALLOW_COPY_AND_ASSIGN(SimpleBubbleView); | 260 DISALLOW_COPY_AND_ASSIGN(SimpleBubbleView); |
261 }; | 261 }; |
262 | 262 |
263 class CustomTooltipView : public View { | |
264 public: | |
265 CustomTooltipView(const base::string16& tooltip, views::View* tooltip_handler) | |
tapted
2016/07/15 06:23:44
nit: remove `views::`
kirr
2016/07/15 07:36:09
Done.
| |
266 : tooltip_(tooltip), tooltip_handler_(tooltip_handler) {} | |
267 | |
268 // Overridden from View: | |
tapted
2016/07/15 06:23:44
nit: just,
// View:
kirr
2016/07/15 07:36:08
Done.
| |
269 bool GetTooltipText(const gfx::Point& p, | |
270 base::string16* tooltip) const override { | |
271 *tooltip = tooltip_; | |
272 return true; | |
273 } | |
274 | |
275 View* GetTooltipHandlerForPoint(const gfx::Point& point) override { | |
276 return tooltip_handler_ ? tooltip_handler_ : this; | |
277 } | |
278 | |
279 private: | |
280 base::string16 tooltip_; | |
281 View* tooltip_handler_; // weak | |
tapted
2016/07/15 06:23:44
nit: // Weak.
kirr
2016/07/15 07:36:09
Done.
| |
282 }; | |
tapted
2016/07/15 06:23:44
nit: DISALLOW_COPY_AND_ASSIGN(CustomTooltipView);
kirr
2016/07/15 07:36:09
Done.
| |
283 | |
263 // Test visibility states triggered externally. | 284 // Test visibility states triggered externally. |
264 TEST_F(NativeWidgetMacTest, HideAndShowExternally) { | 285 TEST_F(NativeWidgetMacTest, HideAndShowExternally) { |
265 Widget* widget = CreateTopLevelPlatformWidget(); | 286 Widget* widget = CreateTopLevelPlatformWidget(); |
266 NSWindow* ns_window = widget->GetNativeWindow(); | 287 NSWindow* ns_window = widget->GetNativeWindow(); |
267 WidgetChangeObserver observer(widget); | 288 WidgetChangeObserver observer(widget); |
268 | 289 |
269 // Should initially be hidden. | 290 // Should initially be hidden. |
270 EXPECT_FALSE(widget->IsVisible()); | 291 EXPECT_FALSE(widget->IsVisible()); |
271 EXPECT_FALSE([ns_window isVisible]); | 292 EXPECT_FALSE([ns_window isVisible]); |
272 EXPECT_EQ(0, observer.gained_visible_count()); | 293 EXPECT_EQ(0, observer.gained_visible_count()); |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
802 event_generator.MoveMouseTo(gfx::Point(15, 15)); | 823 event_generator.MoveMouseTo(gfx::Point(15, 15)); |
803 EXPECT_EQ(tooltip_back, TooltipTextForWidget(widget)); | 824 EXPECT_EQ(tooltip_back, TooltipTextForWidget(widget)); |
804 | 825 |
805 // Move the mouse off of any view, tooltip should clear. | 826 // Move the mouse off of any view, tooltip should clear. |
806 event_generator.MoveMouseTo(gfx::Point(5, 5)); | 827 event_generator.MoveMouseTo(gfx::Point(5, 5)); |
807 EXPECT_TRUE(TooltipTextForWidget(widget).empty()); | 828 EXPECT_TRUE(TooltipTextForWidget(widget).empty()); |
808 | 829 |
809 widget->CloseNow(); | 830 widget->CloseNow(); |
810 } | 831 } |
811 | 832 |
833 // Tests case when mouse events handles in one widget, | |
tapted
2016/07/15 06:23:44
nit: handles->are handled, widget->Widget
(also t
kirr
2016/07/15 07:36:08
Done.
| |
834 // but tooltip belongs to another. | |
835 // It happens in menu widgets, when submenu is shown above parent | |
tapted
2016/07/15 06:23:44
nit: It happens in menus when a submenu is shown a
kirr
2016/07/15 07:36:09
Done.
| |
836 // and parent get MouseExit event. | |
837 TEST_F(NativeWidgetMacTest, TwoWidgetTooltips) { | |
838 // Init two widgets, one above another. | |
839 Widget* widget_below = CreateTopLevelPlatformWidget(); | |
840 widget_below->SetBounds(gfx::Rect(50, 50, 200, 200)); | |
841 | |
842 Widget* widget_above = | |
843 CreateChildPlatformWidget(widget_below->GetNativeView()); | |
844 widget_above->SetBounds(gfx::Rect(100, 0, 100, 200)); | |
845 | |
846 const base::string16 tooltip_above = base::ASCIIToUTF16("Front"); | |
847 CustomTooltipView* view_above = new CustomTooltipView(tooltip_above, nullptr); | |
848 view_above->SetBoundsRect(widget_above->GetContentsView()->bounds()); | |
849 widget_above->GetContentsView()->AddChildView(view_above); | |
850 | |
851 CustomTooltipView* view_below = | |
852 new CustomTooltipView(base::ASCIIToUTF16("Back"), view_above); | |
853 view_below->SetBoundsRect(widget_below->GetContentsView()->bounds()); | |
854 widget_below->GetContentsView()->AddChildView(view_below); | |
855 | |
856 widget_below->Show(); | |
857 widget_above->Show(); | |
858 | |
859 // Move mouse above second widget and check that it returns tooltip | |
860 // for second. Despite that event was handled in the first one. | |
861 ui::test::EventGenerator event_generator(GetContext(), | |
862 widget_below->GetNativeWindow()); | |
863 event_generator.MoveMouseTo(gfx::Point(120, 60)); | |
864 EXPECT_EQ(tooltip_above, TooltipTextForWidget(widget_below)); | |
865 | |
866 widget_above->CloseNow(); | |
867 widget_below->CloseNow(); | |
868 } | |
869 | |
812 namespace { | 870 namespace { |
813 | 871 |
814 // Delegate to make Widgets of a provided ui::ModalType. | 872 // Delegate to make Widgets of a provided ui::ModalType. |
815 class ModalDialogDelegate : public DialogDelegateView { | 873 class ModalDialogDelegate : public DialogDelegateView { |
816 public: | 874 public: |
817 explicit ModalDialogDelegate(ui::ModalType modal_type) | 875 explicit ModalDialogDelegate(ui::ModalType modal_type) |
818 : modal_type_(modal_type) {} | 876 : modal_type_(modal_type) {} |
819 | 877 |
820 // WidgetDelegate: | 878 // WidgetDelegate: |
821 ui::ModalType GetModalType() const override { return modal_type_; } | 879 ui::ModalType GetModalType() const override { return modal_type_; } |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1699 | 1757 |
1700 - (void)dealloc { | 1758 - (void)dealloc { |
1701 if (deallocFlag_) { | 1759 if (deallocFlag_) { |
1702 DCHECK(!*deallocFlag_); | 1760 DCHECK(!*deallocFlag_); |
1703 *deallocFlag_ = true; | 1761 *deallocFlag_ = true; |
1704 } | 1762 } |
1705 [super dealloc]; | 1763 [super dealloc]; |
1706 } | 1764 } |
1707 | 1765 |
1708 @end | 1766 @end |
OLD | NEW |