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"
21 // The non-client frame view of bubble-styled widgets.
22 class VIEWS_EXPORT BubbleFrameView
: public NonClientFrameView
,
23 public ButtonListener
{
25 // Internal class name.
26 static const char kViewClassName
[];
28 // Insets to make bubble contents align horizontal with the bubble title.
29 // NOTE: this does not take into account whether a title actually exists.
30 static gfx::Insets
GetTitleInsets();
32 explicit BubbleFrameView(const gfx::Insets
& content_margins
);
33 virtual ~BubbleFrameView();
35 // NonClientFrameView overrides:
36 virtual gfx::Rect
GetBoundsForClientView() const OVERRIDE
;
37 virtual gfx::Rect
GetWindowBoundsForClientBounds(
38 const gfx::Rect
& client_bounds
) const OVERRIDE
;
39 virtual int NonClientHitTest(const gfx::Point
& point
) OVERRIDE
;
40 virtual void GetWindowMask(const gfx::Size
& size
,
41 gfx::Path
* window_mask
) OVERRIDE
;
42 virtual void ResetWindowControls() OVERRIDE
;
43 virtual void UpdateWindowIcon() OVERRIDE
;
44 virtual void UpdateWindowTitle() OVERRIDE
;
47 virtual gfx::Insets
GetInsets() const OVERRIDE
;
48 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
49 virtual gfx::Size
GetMinimumSize() OVERRIDE
;
50 virtual void Layout() OVERRIDE
;
51 virtual const char* GetClassName() const OVERRIDE
;
52 virtual void ChildPreferredSizeChanged(View
* child
) OVERRIDE
;
53 virtual void OnThemeChanged() OVERRIDE
;
54 virtual void OnNativeThemeChanged(const ui::NativeTheme
* theme
) OVERRIDE
;
56 // Overridden from ButtonListener:
57 virtual void ButtonPressed(Button
* sender
, const ui::Event
& event
) OVERRIDE
;
59 // Use bubble_border() and SetBubbleBorder(), not border() and SetBorder().
60 BubbleBorder
* bubble_border() const { return bubble_border_
; }
61 void SetBubbleBorder(scoped_ptr
<BubbleBorder
> border
);
63 gfx::Insets
content_margins() const { return content_margins_
; }
65 void SetTitlebarExtraView(View
* view
);
67 // Given the size of the contents and the rect to point at, returns the bounds
68 // of the bubble window. The bubble's arrow location may change if the bubble
69 // does not fit on the monitor and |adjust_if_offscreen| is true.
70 gfx::Rect
GetUpdatedWindowBounds(const gfx::Rect
& anchor_rect
,
71 gfx::Size client_size
,
72 bool adjust_if_offscreen
);
75 // Returns the available screen bounds if the frame were to show in |rect|.
76 virtual gfx::Rect
GetAvailableScreenBounds(const gfx::Rect
& rect
);
79 FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest
, GetBoundsForClientView
);
81 // Mirrors the bubble's arrow location on the |vertical| or horizontal axis,
82 // if the generated window bounds don't fit in the monitor bounds.
83 void MirrorArrowIfOffScreen(bool vertical
,
84 const gfx::Rect
& anchor_rect
,
85 const gfx::Size
& client_size
);
87 // Adjust the bubble's arrow offsets if the generated window bounds don't fit
88 // in the monitor bounds.
89 void OffsetArrowIfOffScreen(const gfx::Rect
& anchor_rect
,
90 const gfx::Size
& client_size
);
92 // Calculates the size needed to accommodate the given client area.
93 gfx::Size
GetSizeForClientSize(const gfx::Size
& client_size
);
96 BubbleBorder
* bubble_border_
;
98 // Margins between the content and the inside of the border, in pixels.
99 gfx::Insets content_margins_
;
101 // The optional title and (x) close button.
105 // When supplied, this view is placed in the titlebar between the title and
107 View
* titlebar_extra_view_
;
109 DISALLOW_COPY_AND_ASSIGN(BubbleFrameView
);
114 #endif // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_