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. 4 5 #ifndef UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ 6 #define UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ 7 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" 14 15 namespace gfx { 16 class FontList; 17 } 18 19 namespace views { 20 21 class Label; 22 class LabelButton; 23 class BubbleBorder; 24 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[]; 31 32 // Insets to make bubble contents align horizontal with the bubble title. 33 // NOTE: this does not take into account whether a title actually exists. 34 static gfx::Insets GetTitleInsets(); 35 36 explicit BubbleFrameView(const gfx::Insets& content_margins); 37 virtual ~BubbleFrameView(); 38 39 // NonClientFrameView overrides: 40 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; 41 virtual gfx::Rect GetWindowBoundsForClientBounds( 42 const gfx::Rect& client_bounds) const OVERRIDE; 43 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; 44 virtual void GetWindowMask(const gfx::Size& size, 45 gfx::Path* window_mask) OVERRIDE; 46 virtual void ResetWindowControls() OVERRIDE; 47 virtual void UpdateWindowIcon() OVERRIDE; 48 virtual void UpdateWindowTitle() OVERRIDE; 49 virtual void SizeConstraintsChanged() OVERRIDE; 50 51 // Set the FontList to be used for the title of the bubble. 52 // Caller must arrange to update the layout to have the call take effect. 53 void SetTitleFontList(const gfx::FontList& font_list); 54 55 // View overrides: 56 virtual gfx::Insets GetInsets() const OVERRIDE; 57 virtual gfx::Size GetPreferredSize() const OVERRIDE; 58 virtual gfx::Size GetMinimumSize() const OVERRIDE; 59 virtual void Layout() OVERRIDE; 60 virtual const char* GetClassName() const OVERRIDE; 61 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; 62 virtual void OnThemeChanged() OVERRIDE; 63 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; 64 65 // Overridden from ButtonListener: 66 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE; 67 68 // Use bubble_border() and SetBubbleBorder(), not border() and SetBorder(). 69 BubbleBorder* bubble_border() const { return bubble_border_; } 70 void SetBubbleBorder(scoped_ptr<BubbleBorder> border); 71 72 gfx::Insets content_margins() const { return content_margins_; } 73 74 void SetTitlebarExtraView(View* view); 75 76 // Given the size of the contents and the rect to point at, returns the bounds 77 // of the bubble window. The bubble's arrow location may change if the bubble 78 // does not fit on the monitor and |adjust_if_offscreen| is true. 79 gfx::Rect GetUpdatedWindowBounds(const gfx::Rect& anchor_rect, 80 gfx::Size client_size, 81 bool adjust_if_offscreen); 82 83 protected: 84 // Returns the available screen bounds if the frame were to show in |rect|. 85 virtual gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect); 86 87 private: 88 FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewTest, GetBoundsForClientView); 89 90 // Mirrors the bubble's arrow location on the |vertical| or horizontal axis, 91 // if the generated window bounds don't fit in the monitor bounds. 92 void MirrorArrowIfOffScreen(bool vertical, 93 const gfx::Rect& anchor_rect, 94 const gfx::Size& client_size); 95 96 // Adjust the bubble's arrow offsets if the generated window bounds don't fit 97 // in the monitor bounds. 98 void OffsetArrowIfOffScreen(const gfx::Rect& anchor_rect, 99 const gfx::Size& client_size); 100 101 // Calculates the size needed to accommodate the given client area. 102 gfx::Size GetSizeForClientSize(const gfx::Size& client_size) const; 103 104 // The bubble border. 105 BubbleBorder* bubble_border_; 106 107 // Margins between the content and the inside of the border, in pixels. 108 gfx::Insets content_margins_; 109 110 // The optional title and (x) close button. 111 Label* title_; 112 LabelButton* close_; 113 114 // When supplied, this view is placed in the titlebar between the title and 115 // (x) close button. 116 View* titlebar_extra_view_; 117 118 DISALLOW_COPY_AND_ASSIGN(BubbleFrameView); 119 }; 120 121 } // namespace views 122 123 #endif // UI_VIEWS_BUBBLE_BUBBLE_FRAME_VIEW_H_ 124