OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FRAME_VIEW_H_ | 5 #ifndef UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ |
6 #define UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ | 6 #define UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "ui/gfx/font_list.h" |
11 #include "ui/gfx/geometry/insets.h" | 12 #include "ui/gfx/geometry/insets.h" |
12 #include "ui/views/controls/button/button.h" | 13 #include "ui/views/controls/button/button.h" |
| 14 #include "ui/views/controls/label.h" |
13 #include "ui/views/window/non_client_view.h" | 15 #include "ui/views/window/non_client_view.h" |
14 | 16 |
15 namespace gfx { | |
16 class FontList; | |
17 } | |
18 | |
19 namespace views { | 17 namespace views { |
20 | 18 |
21 class Label; | |
22 class BubbleBorder; | 19 class BubbleBorder; |
23 class ImageView; | 20 class ImageView; |
24 | 21 |
25 // The non-client frame view of bubble-styled widgets. | 22 // The non-client frame view of bubble-styled widgets. |
26 class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView, | 23 class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView, |
27 public ButtonListener { | 24 public ButtonListener { |
28 public: | 25 public: |
29 // Internal class name. | 26 // Internal class name. |
30 static const char kViewClassName[]; | 27 static const char kViewClassName[]; |
31 | 28 |
32 BubbleFrameView(const gfx::Insets& title_margins, | 29 BubbleFrameView(const gfx::Insets& title_margins, |
33 const gfx::Insets& content_margins); | 30 const gfx::Insets& content_margins); |
34 ~BubbleFrameView() override; | 31 ~BubbleFrameView() override; |
35 | 32 |
| 33 static std::unique_ptr<Label> CreateDefaultTitleLabel( |
| 34 const base::string16& title_text); |
| 35 |
36 // Creates a close button used in the corner of the dialog. | 36 // Creates a close button used in the corner of the dialog. |
37 static Button* CreateCloseButton(ButtonListener* listener); | 37 static Button* CreateCloseButton(ButtonListener* listener); |
38 | 38 |
39 // NonClientFrameView: | 39 // NonClientFrameView: |
40 gfx::Rect GetBoundsForClientView() const override; | 40 gfx::Rect GetBoundsForClientView() const override; |
41 gfx::Rect GetWindowBoundsForClientBounds( | 41 gfx::Rect GetWindowBoundsForClientBounds( |
42 const gfx::Rect& client_bounds) const override; | 42 const gfx::Rect& client_bounds) const override; |
43 bool GetClientMask(const gfx::Size& size, gfx::Path* path) const override; | 43 bool GetClientMask(const gfx::Size& size, gfx::Path* path) const override; |
44 int NonClientHitTest(const gfx::Point& point) override; | 44 int NonClientHitTest(const gfx::Point& point) override; |
45 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override; | 45 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override; |
46 void ResetWindowControls() override; | 46 void ResetWindowControls() override; |
47 void UpdateWindowIcon() override; | 47 void UpdateWindowIcon() override; |
48 void UpdateWindowTitle() override; | 48 void UpdateWindowTitle() override; |
49 void SizeConstraintsChanged() override; | 49 void SizeConstraintsChanged() override; |
50 | 50 |
51 // Set the FontList to be used for the title of the bubble. | 51 // Sets a custom view to be the dialog title instead of the |default_title_| |
52 // Caller must arrange to update the layout to have the call take effect. | 52 // label. If there is an existing title view it will be deleted. |
53 void SetTitleFontList(const gfx::FontList& font_list); | 53 void SetTitleView(std::unique_ptr<View> title_view); |
54 | 54 |
55 // View: | 55 // View: |
56 const char* GetClassName() const override; | 56 const char* GetClassName() const override; |
57 gfx::Insets GetInsets() const override; | 57 gfx::Insets GetInsets() const override; |
58 gfx::Size CalculatePreferredSize() const override; | 58 gfx::Size CalculatePreferredSize() const override; |
59 gfx::Size GetMinimumSize() const override; | 59 gfx::Size GetMinimumSize() const override; |
60 gfx::Size GetMaximumSize() const override; | 60 gfx::Size GetMaximumSize() const override; |
61 void Layout() override; | 61 void Layout() override; |
62 void OnPaint(gfx::Canvas* canvas) override; | 62 void OnPaint(gfx::Canvas* canvas) override; |
63 void PaintChildren(const ui::PaintContext& context) override; | 63 void PaintChildren(const ui::PaintContext& context) override; |
64 void OnThemeChanged() override; | 64 void OnThemeChanged() override; |
65 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 65 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
66 void ViewHierarchyChanged( | 66 void ViewHierarchyChanged( |
67 const ViewHierarchyChangedDetails& details) override; | 67 const ViewHierarchyChangedDetails& details) override; |
68 | 68 |
69 // ButtonListener: | 69 // ButtonListener: |
70 void ButtonPressed(Button* sender, const ui::Event& event) override; | 70 void ButtonPressed(Button* sender, const ui::Event& event) override; |
71 | 71 |
72 // Use bubble_border() and SetBubbleBorder(), not border() and SetBorder(). | 72 // Use bubble_border() and SetBubbleBorder(), not border() and SetBorder(). |
73 BubbleBorder* bubble_border() const { return bubble_border_; } | 73 BubbleBorder* bubble_border() const { return bubble_border_; } |
74 void SetBubbleBorder(std::unique_ptr<BubbleBorder> border); | 74 void SetBubbleBorder(std::unique_ptr<BubbleBorder> border); |
75 | 75 |
| 76 const View* title() const { |
| 77 return custom_title_ ? custom_title_ : default_title_; |
| 78 } |
| 79 View* title() { |
| 80 return const_cast<View*>( |
| 81 static_cast<const BubbleFrameView*>(this)->title()); |
| 82 } |
| 83 |
76 gfx::Insets content_margins() const { return content_margins_; } | 84 gfx::Insets content_margins() const { return content_margins_; } |
77 | 85 |
78 void SetFootnoteView(View* view); | 86 void SetFootnoteView(View* view); |
79 | 87 |
80 // Given the size of the contents and the rect to point at, returns the bounds | 88 // Given the size of the contents and the rect to point at, returns the bounds |
81 // of the bubble window. The bubble's arrow location may change if the bubble | 89 // of the bubble window. The bubble's arrow location may change if the bubble |
82 // does not fit on the monitor and |adjust_if_offscreen| is true. | 90 // does not fit on the monitor and |adjust_if_offscreen| is true. |
83 gfx::Rect GetUpdatedWindowBounds(const gfx::Rect& anchor_rect, | 91 gfx::Rect GetUpdatedWindowBounds(const gfx::Rect& anchor_rect, |
84 const gfx::Size& client_size, | 92 const gfx::Size& client_size, |
85 bool adjust_if_offscreen); | 93 bool adjust_if_offscreen); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 125 |
118 // The bubble border. | 126 // The bubble border. |
119 BubbleBorder* bubble_border_; | 127 BubbleBorder* bubble_border_; |
120 | 128 |
121 // Margins around the title label. | 129 // Margins around the title label. |
122 gfx::Insets title_margins_; | 130 gfx::Insets title_margins_; |
123 | 131 |
124 // Margins between the content and the inside of the border, in pixels. | 132 // Margins between the content and the inside of the border, in pixels. |
125 gfx::Insets content_margins_; | 133 gfx::Insets content_margins_; |
126 | 134 |
127 // The optional title icon, title, and (x) close button. | 135 // The optional title icon. |
128 views::ImageView* title_icon_; | 136 views::ImageView* title_icon_; |
129 Label* title_; | 137 |
| 138 // One of these fields is used as the dialog title. If SetTitleView is called |
| 139 // the custom title view is stored in |custom_title_| and this class assumes |
| 140 // ownership. Otherwise |default_title_| is used. |
| 141 Label* default_title_; |
| 142 View* custom_title_; |
| 143 |
| 144 // The optional close button (the X). |
130 Button* close_; | 145 Button* close_; |
131 | 146 |
132 // A view to contain the footnote view, if it exists. | 147 // A view to contain the footnote view, if it exists. |
133 View* footnote_container_; | 148 View* footnote_container_; |
134 | 149 |
135 // Whether the close button was clicked. | 150 // Whether the close button was clicked. |
136 bool close_button_clicked_; | 151 bool close_button_clicked_; |
137 | 152 |
138 DISALLOW_COPY_AND_ASSIGN(BubbleFrameView); | 153 DISALLOW_COPY_AND_ASSIGN(BubbleFrameView); |
139 }; | 154 }; |
140 | 155 |
141 } // namespace views | 156 } // namespace views |
142 | 157 |
143 #endif // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ | 158 #endif // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ |
OLD | NEW |