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"
26 // The non-client frame view of bubble-styled widgets.
27 class VIEWS_EXPORT BubbleFrameView
: public NonClientFrameView
,
28 public ButtonListener
{
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
);
59 gfx::Insets
GetInsets() const override
;
60 gfx::Size
GetPreferredSize() const override
;
61 gfx::Size
GetMinimumSize() const override
;
62 void Layout() override
;
63 const char* GetClassName() const override
;
64 void ChildPreferredSizeChanged(View
* child
) override
;
65 void OnThemeChanged() override
;
66 void OnNativeThemeChanged(const ui::NativeTheme
* theme
) override
;
68 // Overridden from ButtonListener:
69 void ButtonPressed(Button
* sender
, const ui::Event
& event
) override
;
71 // Use bubble_border() and SetBubbleBorder(), not border() and SetBorder().
72 BubbleBorder
* bubble_border() const { return bubble_border_
; }
73 void SetBubbleBorder(scoped_ptr
<BubbleBorder
> border
);
75 gfx::Insets
content_margins() const { return content_margins_
; }
77 void SetTitlebarExtraView(View
* view
);
79 // Given the size of the contents and the rect to point at, returns the bounds
80 // of the bubble window. The bubble's arrow location may change if the bubble
81 // does not fit on the monitor and |adjust_if_offscreen| is true.
82 gfx::Rect
GetUpdatedWindowBounds(const gfx::Rect
& anchor_rect
,
83 gfx::Size client_size
,
84 bool adjust_if_offscreen
);
87 // Returns the available screen bounds if the frame were to show in |rect|.
88 virtual gfx::Rect
GetAvailableScreenBounds(const gfx::Rect
& rect
);
90 bool IsCloseButtonVisible() const;
91 gfx::Rect
GetCloseButtonBounds() const;
94 FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest
, GetBoundsForClientView
);
96 // Mirrors the bubble's arrow location on the |vertical| or horizontal axis,
97 // if the generated window bounds don't fit in the monitor bounds.
98 void MirrorArrowIfOffScreen(bool vertical
,
99 const gfx::Rect
& anchor_rect
,
100 const gfx::Size
& client_size
);
102 // Adjust the bubble's arrow offsets if the generated window bounds don't fit
103 // in the monitor bounds.
104 void OffsetArrowIfOffScreen(const gfx::Rect
& anchor_rect
,
105 const gfx::Size
& client_size
);
107 // Calculates the size needed to accommodate the given client area.
108 gfx::Size
GetSizeForClientSize(const gfx::Size
& client_size
) const;
110 // The bubble border.
111 BubbleBorder
* bubble_border_
;
113 // Margins between the content and the inside of the border, in pixels.
114 gfx::Insets content_margins_
;
116 // The optional title icon, title, and (x) close button.
117 views::ImageView
* title_icon_
;
121 // When supplied, this view is placed in the titlebar between the title and
123 View
* titlebar_extra_view_
;
125 DISALLOW_COPY_AND_ASSIGN(BubbleFrameView
);
130 #endif // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_