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"
25 // The non-client frame view of bubble-styled widgets.
26 class VIEWS_EXPORT BubbleFrameView
: public NonClientFrameView
,
27 public ButtonListener
{
29 // Internal class name.
30 static const char kViewClassName
[];
32 explicit BubbleFrameView(const gfx::Insets
& content_margins
);
33 virtual ~BubbleFrameView();
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 virtual gfx::Rect
GetBoundsForClientView() const override
;
44 virtual gfx::Rect
GetWindowBoundsForClientBounds(
45 const gfx::Rect
& client_bounds
) const override
;
46 virtual int NonClientHitTest(const gfx::Point
& point
) override
;
47 virtual void GetWindowMask(const gfx::Size
& size
,
48 gfx::Path
* window_mask
) override
;
49 virtual void ResetWindowControls() override
;
50 virtual void UpdateWindowIcon() override
;
51 virtual void UpdateWindowTitle() override
;
52 virtual 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 virtual gfx::Insets
GetInsets() const override
;
60 virtual gfx::Size
GetPreferredSize() const override
;
61 virtual gfx::Size
GetMinimumSize() const override
;
62 virtual void Layout() override
;
63 virtual const char* GetClassName() const override
;
64 virtual void ChildPreferredSizeChanged(View
* child
) override
;
65 virtual void OnThemeChanged() override
;
66 virtual void OnNativeThemeChanged(const ui::NativeTheme
* theme
) override
;
68 // Overridden from ButtonListener:
69 virtual 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 and (x) close button.
120 // When supplied, this view is placed in the titlebar between the title and
122 View
* titlebar_extra_view_
;
124 DISALLOW_COPY_AND_ASSIGN(BubbleFrameView
);
129 #endif // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_