Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / views / bubble / bubble_frame_view.h
blob044b739757782d332501a950d9b007a2b27e7192
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
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_
6 #define UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/gtest_prod_util.h"
11 #include "ui/gfx/geometry/insets.h"
12 #include "ui/views/controls/button/button.h"
13 #include "ui/views/window/non_client_view.h"
15 namespace gfx {
16 class FontList;
19 namespace views {
21 class Label;
22 class LabelButton;
23 class BubbleBorder;
24 class ImageView;
26 // The non-client frame view of bubble-styled widgets.
27 class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView,
28 public ButtonListener {
29 public:
30 // Internal class name.
31 static const char kViewClassName[];
33 explicit BubbleFrameView(const gfx::Insets& content_margins);
34 ~BubbleFrameView() override;
36 // Insets to make bubble contents align horizontal with the bubble title.
37 // NOTE: this does not take into account whether a title actually exists.
38 static gfx::Insets GetTitleInsets();
40 // Creates a close button used in the corner of the dialog.
41 static LabelButton* CreateCloseButton(ButtonListener* listener);
43 // NonClientFrameView overrides:
44 gfx::Rect GetBoundsForClientView() const override;
45 gfx::Rect GetWindowBoundsForClientBounds(
46 const gfx::Rect& client_bounds) const override;
47 int NonClientHitTest(const gfx::Point& point) override;
48 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override;
49 void ResetWindowControls() override;
50 void UpdateWindowIcon() override;
51 void UpdateWindowTitle() override;
52 void SizeConstraintsChanged() override;
54 // Set the FontList to be used for the title of the bubble.
55 // Caller must arrange to update the layout to have the call take effect.
56 void SetTitleFontList(const gfx::FontList& font_list);
58 // View overrides:
59 gfx::Insets GetInsets() const override;
60 gfx::Size GetPreferredSize() const override;
61 gfx::Size GetMinimumSize() const override;
62 gfx::Size GetMaximumSize() const override;
63 void Layout() override;
64 const char* GetClassName() const override;
65 void ChildPreferredSizeChanged(View* child) override;
66 void OnThemeChanged() override;
67 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
69 // Overridden from ButtonListener:
70 void ButtonPressed(Button* sender, const ui::Event& event) override;
72 // Use bubble_border() and SetBubbleBorder(), not border() and SetBorder().
73 BubbleBorder* bubble_border() const { return bubble_border_; }
74 void SetBubbleBorder(scoped_ptr<BubbleBorder> border);
76 gfx::Insets content_margins() const { return content_margins_; }
78 void SetTitlebarExtraView(View* view);
80 // 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
82 // does not fit on the monitor and |adjust_if_offscreen| is true.
83 gfx::Rect GetUpdatedWindowBounds(const gfx::Rect& anchor_rect,
84 gfx::Size client_size,
85 bool adjust_if_offscreen);
87 protected:
88 // Returns the available screen bounds if the frame were to show in |rect|.
89 virtual gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect);
91 bool IsCloseButtonVisible() const;
92 gfx::Rect GetCloseButtonMirroredBounds() const;
94 private:
95 FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, GetBoundsForClientView);
97 // Mirrors the bubble's arrow location on the |vertical| or horizontal axis,
98 // if the generated window bounds don't fit in the monitor bounds.
99 void MirrorArrowIfOffScreen(bool vertical,
100 const gfx::Rect& anchor_rect,
101 const gfx::Size& client_size);
103 // Adjust the bubble's arrow offsets if the generated window bounds don't fit
104 // in the monitor bounds.
105 void OffsetArrowIfOffScreen(const gfx::Rect& anchor_rect,
106 const gfx::Size& client_size);
108 // Calculates the size needed to accommodate the given client area.
109 gfx::Size GetSizeForClientSize(const gfx::Size& client_size) const;
111 // The bubble border.
112 BubbleBorder* bubble_border_;
114 // Margins between the content and the inside of the border, in pixels.
115 gfx::Insets content_margins_;
117 // The optional title icon, title, and (x) close button.
118 views::ImageView* title_icon_;
119 Label* title_;
120 LabelButton* close_;
122 // When supplied, this view is placed in the titlebar between the title and
123 // (x) close button.
124 View* titlebar_extra_view_;
126 DISALLOW_COPY_AND_ASSIGN(BubbleFrameView);
129 } // namespace views
131 #endif // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_