| 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, View* tooltip_handler) |
| 266 : tooltip_(tooltip), tooltip_handler_(tooltip_handler) {} |
| 267 |
| 268 // View: |
| 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 |
| 282 |
| 283 DISALLOW_COPY_AND_ASSIGN(CustomTooltipView); |
| 284 }; |
| 285 |
| 263 // Test visibility states triggered externally. | 286 // Test visibility states triggered externally. |
| 264 TEST_F(NativeWidgetMacTest, HideAndShowExternally) { | 287 TEST_F(NativeWidgetMacTest, HideAndShowExternally) { |
| 265 Widget* widget = CreateTopLevelPlatformWidget(); | 288 Widget* widget = CreateTopLevelPlatformWidget(); |
| 266 NSWindow* ns_window = widget->GetNativeWindow(); | 289 NSWindow* ns_window = widget->GetNativeWindow(); |
| 267 WidgetChangeObserver observer(widget); | 290 WidgetChangeObserver observer(widget); |
| 268 | 291 |
| 269 // Should initially be hidden. | 292 // Should initially be hidden. |
| 270 EXPECT_FALSE(widget->IsVisible()); | 293 EXPECT_FALSE(widget->IsVisible()); |
| 271 EXPECT_FALSE([ns_window isVisible]); | 294 EXPECT_FALSE([ns_window isVisible]); |
| 272 EXPECT_EQ(0, observer.gained_visible_count()); | 295 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)); | 825 event_generator.MoveMouseTo(gfx::Point(15, 15)); |
| 803 EXPECT_EQ(tooltip_back, TooltipTextForWidget(widget)); | 826 EXPECT_EQ(tooltip_back, TooltipTextForWidget(widget)); |
| 804 | 827 |
| 805 // Move the mouse off of any view, tooltip should clear. | 828 // Move the mouse off of any view, tooltip should clear. |
| 806 event_generator.MoveMouseTo(gfx::Point(5, 5)); | 829 event_generator.MoveMouseTo(gfx::Point(5, 5)); |
| 807 EXPECT_TRUE(TooltipTextForWidget(widget).empty()); | 830 EXPECT_TRUE(TooltipTextForWidget(widget).empty()); |
| 808 | 831 |
| 809 widget->CloseNow(); | 832 widget->CloseNow(); |
| 810 } | 833 } |
| 811 | 834 |
| 835 // Tests case when mouse events are handled in one Widget, |
| 836 // but tooltip belongs to another. |
| 837 // It happens in menus when a submenu is shown and the parent gets the |
| 838 // MouseExit event. |
| 839 TEST_F(NativeWidgetMacTest, TwoWidgetTooltips) { |
| 840 // Init two widgets, one above another. |
| 841 Widget* widget_below = CreateTopLevelPlatformWidget(); |
| 842 widget_below->SetBounds(gfx::Rect(50, 50, 200, 200)); |
| 843 |
| 844 Widget* widget_above = |
| 845 CreateChildPlatformWidget(widget_below->GetNativeView()); |
| 846 widget_above->SetBounds(gfx::Rect(100, 0, 100, 200)); |
| 847 |
| 848 const base::string16 tooltip_above = base::ASCIIToUTF16("Front"); |
| 849 CustomTooltipView* view_above = new CustomTooltipView(tooltip_above, nullptr); |
| 850 view_above->SetBoundsRect(widget_above->GetContentsView()->bounds()); |
| 851 widget_above->GetContentsView()->AddChildView(view_above); |
| 852 |
| 853 CustomTooltipView* view_below = |
| 854 new CustomTooltipView(base::ASCIIToUTF16("Back"), view_above); |
| 855 view_below->SetBoundsRect(widget_below->GetContentsView()->bounds()); |
| 856 widget_below->GetContentsView()->AddChildView(view_below); |
| 857 |
| 858 widget_below->Show(); |
| 859 widget_above->Show(); |
| 860 |
| 861 // Move mouse above second widget and check that it returns tooltip |
| 862 // for second. Despite that event was handled in the first one. |
| 863 ui::test::EventGenerator event_generator(GetContext(), |
| 864 widget_below->GetNativeWindow()); |
| 865 event_generator.MoveMouseTo(gfx::Point(120, 60)); |
| 866 EXPECT_EQ(tooltip_above, TooltipTextForWidget(widget_below)); |
| 867 |
| 868 widget_above->CloseNow(); |
| 869 widget_below->CloseNow(); |
| 870 } |
| 871 |
| 812 namespace { | 872 namespace { |
| 813 | 873 |
| 814 // Delegate to make Widgets of a provided ui::ModalType. | 874 // Delegate to make Widgets of a provided ui::ModalType. |
| 815 class ModalDialogDelegate : public DialogDelegateView { | 875 class ModalDialogDelegate : public DialogDelegateView { |
| 816 public: | 876 public: |
| 817 explicit ModalDialogDelegate(ui::ModalType modal_type) | 877 explicit ModalDialogDelegate(ui::ModalType modal_type) |
| 818 : modal_type_(modal_type) {} | 878 : modal_type_(modal_type) {} |
| 819 | 879 |
| 820 // WidgetDelegate: | 880 // WidgetDelegate: |
| 821 ui::ModalType GetModalType() const override { return modal_type_; } | 881 ui::ModalType GetModalType() const override { return modal_type_; } |
| (...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1699 | 1759 |
| 1700 - (void)dealloc { | 1760 - (void)dealloc { |
| 1701 if (deallocFlag_) { | 1761 if (deallocFlag_) { |
| 1702 DCHECK(!*deallocFlag_); | 1762 DCHECK(!*deallocFlag_); |
| 1703 *deallocFlag_ = true; | 1763 *deallocFlag_ = true; |
| 1704 } | 1764 } |
| 1705 [super dealloc]; | 1765 [super dealloc]; |
| 1706 } | 1766 } |
| 1707 | 1767 |
| 1708 @end | 1768 @end |
| OLD | NEW |