| 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. The title view is owned by this BubbleFrameView. If there is an |
| 53 void SetTitleFontList(const gfx::FontList& font_list); | 53 // existing title view it will be deleted. |
| 54 void SetTitleView(View* title_view); |
| 54 | 55 |
| 55 // View: | 56 // View: |
| 56 const char* GetClassName() const override; | 57 const char* GetClassName() const override; |
| 57 gfx::Insets GetInsets() const override; | 58 gfx::Insets GetInsets() const override; |
| 58 gfx::Size CalculatePreferredSize() const override; | 59 gfx::Size CalculatePreferredSize() const override; |
| 59 gfx::Size GetMinimumSize() const override; | 60 gfx::Size GetMinimumSize() const override; |
| 60 gfx::Size GetMaximumSize() const override; | 61 gfx::Size GetMaximumSize() const override; |
| 61 void Layout() override; | 62 void Layout() override; |
| 62 void OnPaint(gfx::Canvas* canvas) override; | 63 void OnPaint(gfx::Canvas* canvas) override; |
| 63 void PaintChildren(const ui::PaintContext& context) override; | 64 void PaintChildren(const ui::PaintContext& context) override; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 94 | 95 |
| 95 bool IsCloseButtonVisible() const; | 96 bool IsCloseButtonVisible() const; |
| 96 gfx::Rect GetCloseButtonMirroredBounds() const; | 97 gfx::Rect GetCloseButtonMirroredBounds() const; |
| 97 | 98 |
| 98 private: | 99 private: |
| 99 FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, GetBoundsForClientView); | 100 FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, GetBoundsForClientView); |
| 100 FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, RemoveFootnoteView); | 101 FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, RemoveFootnoteView); |
| 101 FRIEND_TEST_ALL_PREFIXES(BubbleDelegateTest, CloseReasons); | 102 FRIEND_TEST_ALL_PREFIXES(BubbleDelegateTest, CloseReasons); |
| 102 FRIEND_TEST_ALL_PREFIXES(BubbleDialogDelegateTest, CloseMethods); | 103 FRIEND_TEST_ALL_PREFIXES(BubbleDialogDelegateTest, CloseMethods); |
| 103 | 104 |
| 105 const View* title() const { |
| 106 return custom_title_ ? custom_title_ : default_title_; |
| 107 } |
| 108 View* title() { |
| 109 return const_cast<View*>( |
| 110 static_cast<const BubbleFrameView*>(this)->title()); |
| 111 } |
| 112 |
| 104 // Mirrors the bubble's arrow location on the |vertical| or horizontal axis, | 113 // Mirrors the bubble's arrow location on the |vertical| or horizontal axis, |
| 105 // if the generated window bounds don't fit in the monitor bounds. | 114 // if the generated window bounds don't fit in the monitor bounds. |
| 106 void MirrorArrowIfOffScreen(bool vertical, | 115 void MirrorArrowIfOffScreen(bool vertical, |
| 107 const gfx::Rect& anchor_rect, | 116 const gfx::Rect& anchor_rect, |
| 108 const gfx::Size& client_size); | 117 const gfx::Size& client_size); |
| 109 | 118 |
| 110 // Adjust the bubble's arrow offsets if the generated window bounds don't fit | 119 // Adjust the bubble's arrow offsets if the generated window bounds don't fit |
| 111 // in the monitor bounds. | 120 // in the monitor bounds. |
| 112 void OffsetArrowIfOffScreen(const gfx::Rect& anchor_rect, | 121 void OffsetArrowIfOffScreen(const gfx::Rect& anchor_rect, |
| 113 const gfx::Size& client_size); | 122 const gfx::Size& client_size); |
| 114 | 123 |
| 115 // Calculates the size needed to accommodate the given client area. | 124 // Calculates the size needed to accommodate the given client area. |
| 116 gfx::Size GetSizeForClientSize(const gfx::Size& client_size) const; | 125 gfx::Size GetSizeForClientSize(const gfx::Size& client_size) const; |
| 117 | 126 |
| 118 // The bubble border. | 127 // The bubble border. |
| 119 BubbleBorder* bubble_border_; | 128 BubbleBorder* bubble_border_; |
| 120 | 129 |
| 121 // Margins around the title label. | 130 // Margins around the title label. |
| 122 gfx::Insets title_margins_; | 131 gfx::Insets title_margins_; |
| 123 | 132 |
| 124 // Margins between the content and the inside of the border, in pixels. | 133 // Margins between the content and the inside of the border, in pixels. |
| 125 gfx::Insets content_margins_; | 134 gfx::Insets content_margins_; |
| 126 | 135 |
| 127 // The optional title icon, title, and (x) close button. | 136 // The optional title icon. |
| 128 views::ImageView* title_icon_; | 137 views::ImageView* title_icon_; |
| 129 Label* title_; | 138 |
| 139 // One of these fields is used as the dialog title. If SetTitleView is called |
| 140 // the custom title view is stored in |custom_title_| and this class assumes |
| 141 // ownership. Otherwise |default_title_| is used. |
| 142 Label* default_title_; |
| 143 View* custom_title_; |
| 144 |
| 145 // The optional close button (the X). |
| 130 Button* close_; | 146 Button* close_; |
| 131 | 147 |
| 132 // A view to contain the footnote view, if it exists. | 148 // A view to contain the footnote view, if it exists. |
| 133 View* footnote_container_; | 149 View* footnote_container_; |
| 134 | 150 |
| 135 // Whether the close button was clicked. | 151 // Whether the close button was clicked. |
| 136 bool close_button_clicked_; | 152 bool close_button_clicked_; |
| 137 | 153 |
| 138 DISALLOW_COPY_AND_ASSIGN(BubbleFrameView); | 154 DISALLOW_COPY_AND_ASSIGN(BubbleFrameView); |
| 139 }; | 155 }; |
| 140 | 156 |
| 141 } // namespace views | 157 } // namespace views |
| 142 | 158 |
| 143 #endif // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ | 159 #endif // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ |
| OLD | NEW |