OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef UI_VIEWS_BUBBLE_BUBBLE_DELEGATE_H_ | 5 #ifndef UI_VIEWS_BUBBLE_BUBBLE_DIALOG_DELEGATE_H_ |
6 #define UI_VIEWS_BUBBLE_BUBBLE_DELEGATE_H_ | 6 #define UI_VIEWS_BUBBLE_BUBBLE_DIALOG_DELEGATE_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "ui/views/bubble/bubble_border.h" | 10 #include "ui/views/bubble/bubble_border.h" |
11 #include "ui/views/widget/widget.h" | 11 #include "ui/views/widget/widget.h" |
12 #include "ui/views/widget/widget_delegate.h" | |
13 #include "ui/views/widget/widget_observer.h" | 12 #include "ui/views/widget/widget_observer.h" |
| 13 #include "ui/views/window/dialog_delegate.h" |
14 | 14 |
15 namespace gfx { | 15 namespace gfx { |
16 class FontList; | 16 class FontList; |
17 class Rect; | 17 class Rect; |
18 } | 18 } |
19 | 19 |
20 namespace views { | 20 namespace views { |
21 | 21 |
22 class BubbleFrameView; | 22 class BubbleFrameView; |
23 | 23 |
24 // BubbleDelegateView creates frame and client views for bubble Widgets. | 24 // BubbleDialogDelegateView is a special DialogDelegateView for bubbles. |
25 // BubbleDelegateView itself is the client's contents view. | 25 class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView, |
26 class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, | 26 public WidgetObserver { |
27 public WidgetObserver { | |
28 public: | 27 public: |
29 // Internal class name. | 28 // Internal class name. |
30 static const char kViewClassName[]; | 29 static const char kViewClassName[]; |
31 | 30 |
32 enum class CloseReason { | 31 enum class CloseReason { |
33 DEACTIVATION, | 32 DEACTIVATION, |
34 ESCAPE, | 33 ESCAPE, |
35 CLOSE_BUTTON, | 34 CLOSE_BUTTON, |
36 UNKNOWN, | 35 UNKNOWN, |
37 }; | 36 }; |
38 | 37 |
39 BubbleDelegateView(); | 38 ~BubbleDialogDelegateView() override; |
40 BubbleDelegateView(View* anchor_view, BubbleBorder::Arrow arrow); | |
41 ~BubbleDelegateView() override; | |
42 | 39 |
43 // Create and initialize the bubble Widget(s) with proper bounds. | 40 // Create and initialize the bubble Widget(s) with proper bounds. |
44 static Widget* CreateBubble(BubbleDelegateView* bubble_delegate); | 41 static Widget* CreateBubble(BubbleDialogDelegateView* bubble_delegate); |
45 | 42 |
46 // WidgetDelegateView overrides: | 43 // WidgetDelegateView overrides: |
47 BubbleDelegateView* AsBubbleDelegate() override; | |
48 bool ShouldShowCloseButton() const override; | 44 bool ShouldShowCloseButton() const override; |
49 View* GetContentsView() override; | 45 ClientView* CreateClientView(Widget* widget) override; |
50 NonClientFrameView* CreateNonClientFrameView(Widget* widget) override; | 46 NonClientFrameView* CreateNonClientFrameView(Widget* widget) override; |
51 void GetAccessibleState(ui::AXViewState* state) override; | 47 void GetAccessibleState(ui::AXViewState* state) override; |
52 const char* GetClassName() const override; | 48 const char* GetClassName() const override; |
53 | 49 |
54 // WidgetObserver overrides: | 50 // WidgetObserver overrides: |
55 void OnWidgetClosing(Widget* widget) override; | 51 void OnWidgetClosing(Widget* widget) override; |
56 void OnWidgetDestroying(Widget* widget) override; | 52 void OnWidgetDestroying(Widget* widget) override; |
57 void OnWidgetVisibilityChanging(Widget* widget, bool visible) override; | 53 void OnWidgetVisibilityChanging(Widget* widget, bool visible) override; |
58 void OnWidgetVisibilityChanged(Widget* widget, bool visible) override; | 54 void OnWidgetVisibilityChanged(Widget* widget, bool visible) override; |
59 void OnWidgetActivationChanged(Widget* widget, bool active) override; | 55 void OnWidgetActivationChanged(Widget* widget, bool active) override; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 100 |
105 CloseReason close_reason() const { return close_reason_; } | 101 CloseReason close_reason() const { return close_reason_; } |
106 | 102 |
107 // Get the arrow's anchor rect in screen space. | 103 // Get the arrow's anchor rect in screen space. |
108 virtual gfx::Rect GetAnchorRect() const; | 104 virtual gfx::Rect GetAnchorRect() const; |
109 | 105 |
110 // Allows delegates to provide custom parameters before widget initialization. | 106 // Allows delegates to provide custom parameters before widget initialization. |
111 virtual void OnBeforeBubbleWidgetInit(Widget::InitParams* params, | 107 virtual void OnBeforeBubbleWidgetInit(Widget::InitParams* params, |
112 Widget* widget) const; | 108 Widget* widget) const; |
113 | 109 |
114 // Creates and returns a view to be displayed at the bottom of the bubble. | |
115 virtual scoped_ptr<View> CreateFootnoteView(); | |
116 | |
117 // Sets |margins_| to a default picked for smaller bubbles. | 110 // Sets |margins_| to a default picked for smaller bubbles. |
118 void UseCompactMargins(); | 111 void UseCompactMargins(); |
119 | 112 |
120 // Sets the bubble alignment relative to the anchor. This may only be called | 113 // Sets the bubble alignment relative to the anchor. This may only be called |
121 // after calling CreateBubble. | 114 // after calling CreateBubble. |
122 void SetAlignment(BubbleBorder::BubbleAlignment alignment); | 115 void SetAlignment(BubbleBorder::BubbleAlignment alignment); |
123 | 116 |
124 // Sets the bubble arrow paint type. | 117 // Sets the bubble arrow paint type. |
125 void SetArrowPaintType(BubbleBorder::ArrowPaintType paint_type); | 118 void SetArrowPaintType(BubbleBorder::ArrowPaintType paint_type); |
126 | 119 |
127 // Call this method when the anchor bounds have changed to reposition the | 120 // Call this method when the anchor bounds have changed to reposition the |
128 // bubble. The bubble is automatically repositioned when the anchor view | 121 // bubble. The bubble is automatically repositioned when the anchor view |
129 // bounds change as a result of the widget's bounds changing. | 122 // bounds change as a result of the widget's bounds changing. |
130 void OnAnchorBoundsChanged(); | 123 void OnAnchorBoundsChanged(); |
131 | 124 |
132 protected: | 125 protected: |
| 126 BubbleDialogDelegateView(); |
| 127 BubbleDialogDelegateView(View* anchor_view, BubbleBorder::Arrow arrow); |
| 128 |
133 // Get bubble bounds from the anchor rect and client view's preferred size. | 129 // Get bubble bounds from the anchor rect and client view's preferred size. |
134 virtual gfx::Rect GetBubbleBounds(); | 130 virtual gfx::Rect GetBubbleBounds(); |
135 | 131 |
136 // Return a FontList to use for the title of the bubble. | 132 // Return a FontList to use for the title of the bubble. |
137 // (The default is MediumFont). | 133 // (The default is MediumFont). |
138 virtual const gfx::FontList& GetTitleFontList() const; | 134 virtual const gfx::FontList& GetTitleFontList() const; |
139 | 135 |
140 // View overrides: | 136 // View overrides: |
141 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 137 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
142 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 138 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 200 |
205 // If true (defaults to true), the arrow may be mirrored and moved to fit the | 201 // If true (defaults to true), the arrow may be mirrored and moved to fit the |
206 // bubble on screen better. It would be a no-op if the bubble has no arrow. | 202 // bubble on screen better. It would be a no-op if the bubble has no arrow. |
207 bool adjust_if_offscreen_; | 203 bool adjust_if_offscreen_; |
208 | 204 |
209 // Parent native window of the bubble. | 205 // Parent native window of the bubble. |
210 gfx::NativeView parent_window_; | 206 gfx::NativeView parent_window_; |
211 | 207 |
212 CloseReason close_reason_; | 208 CloseReason close_reason_; |
213 | 209 |
214 DISALLOW_COPY_AND_ASSIGN(BubbleDelegateView); | 210 DISALLOW_COPY_AND_ASSIGN(BubbleDialogDelegateView); |
215 }; | 211 }; |
216 | 212 |
217 } // namespace views | 213 } // namespace views |
218 | 214 |
219 #endif // UI_VIEWS_BUBBLE_BUBBLE_DELEGATE_H_ | 215 #endif // UI_VIEWS_BUBBLE_BUBBLE_DELEGATE2_H_ |
OLD | NEW |