Add include.
[chromium-blink-merge.git] / ui / views / bubble / bubble_frame_view.h
blobcfe14330f0b52b99130e08ad2378f236f53edcbf
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/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;
25 // The non-client frame view of bubble-styled widgets.
26 class VIEWS_EXPORT BubbleFrameView : public NonClientFrameView,
27 public ButtonListener {
28 public:
29 // Internal class name.
30 static const char kViewClassName[];
32 explicit BubbleFrameView(const gfx::Insets& content_margins);
33 ~BubbleFrameView() override;
35 // Insets to make bubble contents align horizontal with the bubble title.
36 // NOTE: this does not take into account whether a title actually exists.
37 static gfx::Insets GetTitleInsets();
39 // Creates a close button used in the corner of the dialog.
40 static LabelButton* CreateCloseButton(ButtonListener* listener);
42 // NonClientFrameView overrides:
43 gfx::Rect GetBoundsForClientView() const override;
44 gfx::Rect GetWindowBoundsForClientBounds(
45 const gfx::Rect& client_bounds) const override;
46 int NonClientHitTest(const gfx::Point& point) override;
47 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override;
48 void ResetWindowControls() override;
49 void UpdateWindowIcon() override;
50 void UpdateWindowTitle() override;
51 void SizeConstraintsChanged() override;
53 // Set the FontList to be used for the title of the bubble.
54 // Caller must arrange to update the layout to have the call take effect.
55 void SetTitleFontList(const gfx::FontList& font_list);
57 // View overrides:
58 gfx::Insets GetInsets() const override;
59 gfx::Size GetPreferredSize() const override;
60 gfx::Size GetMinimumSize() const override;
61 void Layout() override;
62 const char* GetClassName() const override;
63 void ChildPreferredSizeChanged(View* child) override;
64 void OnThemeChanged() override;
65 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
67 // Overridden from ButtonListener:
68 void ButtonPressed(Button* sender, const ui::Event& event) override;
70 // Use bubble_border() and SetBubbleBorder(), not border() and SetBorder().
71 BubbleBorder* bubble_border() const { return bubble_border_; }
72 void SetBubbleBorder(scoped_ptr<BubbleBorder> border);
74 gfx::Insets content_margins() const { return content_margins_; }
76 void SetTitlebarExtraView(View* view);
78 // Given the size of the contents and the rect to point at, returns the bounds
79 // of the bubble window. The bubble's arrow location may change if the bubble
80 // does not fit on the monitor and |adjust_if_offscreen| is true.
81 gfx::Rect GetUpdatedWindowBounds(const gfx::Rect& anchor_rect,
82 gfx::Size client_size,
83 bool adjust_if_offscreen);
85 protected:
86 // Returns the available screen bounds if the frame were to show in |rect|.
87 virtual gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect);
89 bool IsCloseButtonVisible() const;
90 gfx::Rect GetCloseButtonBounds() const;
92 private:
93 FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, GetBoundsForClientView);
95 // Mirrors the bubble's arrow location on the |vertical| or horizontal axis,
96 // if the generated window bounds don't fit in the monitor bounds.
97 void MirrorArrowIfOffScreen(bool vertical,
98 const gfx::Rect& anchor_rect,
99 const gfx::Size& client_size);
101 // Adjust the bubble's arrow offsets if the generated window bounds don't fit
102 // in the monitor bounds.
103 void OffsetArrowIfOffScreen(const gfx::Rect& anchor_rect,
104 const gfx::Size& client_size);
106 // Calculates the size needed to accommodate the given client area.
107 gfx::Size GetSizeForClientSize(const gfx::Size& client_size) const;
109 // The bubble border.
110 BubbleBorder* bubble_border_;
112 // Margins between the content and the inside of the border, in pixels.
113 gfx::Insets content_margins_;
115 // The optional title and (x) close button.
116 Label* title_;
117 LabelButton* close_;
119 // When supplied, this view is placed in the titlebar between the title and
120 // (x) close button.
121 View* titlebar_extra_view_;
123 DISALLOW_COPY_AND_ASSIGN(BubbleFrameView);
126 } // namespace views
128 #endif // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_