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 CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_NON_CLIENT_FRAME_VIEW_H_ 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_NON_CLIENT_FRAME_VIEW_H_ 7 8 #include "base/scoped_observer.h" 9 #include "build/build_config.h" 10 #include "chrome/browser/profiles/profile_attributes_storage.h" 11 #include "chrome/browser/ui/views/tabs/tab_strip.h" 12 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h" 13 #include "chrome/browser/ui/views/tabs/tab_strip_types.h" 14 #include "ui/views/widget/widget.h" 15 #include "ui/views/window/non_client_view.h" 16 17 class BrowserFrame; 18 class BrowserView; 19 class WebAppFrameToolbarView; 20 21 // Type used for functions whose return values depend on the active state of 22 // the frame. 23 enum class BrowserFrameActiveState { 24 kUseCurrent, // Use current frame active state. 25 kActive, // Treat frame as active regardless of current state. 26 kInactive, // Treat frame as inactive regardless of current state. 27 }; 28 29 // A specialization of the NonClientFrameView object that provides additional 30 // Browser-specific methods. 31 class BrowserNonClientFrameView : public views::NonClientFrameView, 32 public ProfileAttributesStorage::Observer, 33 public TabStripObserver { 34 public: 35 // The minimum total height users should have to use as a drag handle to move 36 // the window with. 37 static constexpr int kMinimumDragHeight = 8; 38 39 BrowserNonClientFrameView(BrowserFrame* frame, BrowserView* browser_view); 40 ~BrowserNonClientFrameView() override; 41 browser_view()42 BrowserView* browser_view() const { return browser_view_; } frame()43 BrowserFrame* frame() const { return frame_; } 44 45 // Called when BrowserView creates all it's child views. 46 virtual void OnBrowserViewInitViewsComplete(); 47 48 // Called on Mac after the browser window is fullscreened or unfullscreened. 49 virtual void OnFullscreenStateChanged(); 50 51 // Returns whether the caption buttons are drawn at the leading edge (i.e. the 52 // left in LTR mode, or the right in RTL mode). 53 virtual bool CaptionButtonsOnLeadingEdge() const; 54 55 // Retrieves the bounds in non-client view coordinates within which the 56 // TabStrip should be laid out. 57 virtual gfx::Rect GetBoundsForTabStripRegion( 58 const gfx::Size& tabstrip_minimum_size) const = 0; 59 60 // Returns the inset of the topmost view in the client view from the top of 61 // the non-client view. The topmost view depends on the window type. The 62 // topmost view is the tab strip for tabbed browser windows, the toolbar for 63 // popups, the web contents for app windows and varies for fullscreen windows. 64 // If |restored| is true, this is calculated as if the window was restored, 65 // regardless of its current state. 66 virtual int GetTopInset(bool restored) const = 0; 67 68 // Returns the amount that the theme background should be inset. 69 virtual int GetThemeBackgroundXInset() const = 0; 70 71 // Updates the top UI state to be hidden or shown in fullscreen according to 72 // the preference's state. Currently only used on Mac. 73 virtual void UpdateFullscreenTopUI(); 74 75 // Returns whether the top UI should hide. 76 virtual bool ShouldHideTopUIForFullscreen() const; 77 78 // Returns whether the user is allowed to exit fullscreen on their own (some 79 // special modes lock the user in fullscreen). 80 virtual bool CanUserExitFullscreen() const; 81 82 // Determines whether the top frame is condensed vertically, as when the 83 // window is maximized. If true, the top frame is just the height of a tab, 84 // rather than having extra vertical space above the tabs. 85 virtual bool IsFrameCondensed() const; 86 87 // Returns whether the shapes of background tabs are visible against the 88 // frame, given an active state of |active|. 89 virtual bool HasVisibleBackgroundTabShapes( 90 BrowserFrameActiveState active_state) const; 91 92 // Returns whether the shapes of background tabs are visible against the frame 93 // for either active or inactive windows. 94 bool EverHasVisibleBackgroundTabShapes() const; 95 96 // Returns whether tab strokes can be drawn. 97 virtual bool CanDrawStrokes() const; 98 99 // Returns the color to use for text, caption buttons, and other title bar 100 // elements. 101 virtual SkColor GetCaptionColor(BrowserFrameActiveState active_state) const; 102 103 // Returns the color of the browser frame, which is also the color of the 104 // tabstrip background. 105 SkColor GetFrameColor(BrowserFrameActiveState active_state = 106 BrowserFrameActiveState::kUseCurrent) const; 107 108 // Called by BrowserView to signal the frame color has changed and needs 109 // to be repainted. 110 virtual void UpdateFrameColor(); 111 112 // Returns COLOR_TOOLBAR_TOP_SEPARATOR[,_INACTIVE] depending on the activation 113 // state of the window. 114 SkColor GetToolbarTopSeparatorColor() const; 115 116 // For non-transparent windows, returns the background tab image resource ID 117 // if the image has been customized, directly or indirectly, by the theme. 118 base::Optional<int> GetCustomBackgroundId( 119 BrowserFrameActiveState active_state) const; 120 121 // Updates the throbber. 122 virtual void UpdateThrobber(bool running) = 0; 123 124 // Provided for platform-specific updates of minimum window size. 125 virtual void UpdateMinimumSize(); 126 127 // views::NonClientFrameView: 128 using views::NonClientFrameView::ShouldPaintAsActive; 129 void Layout() override; 130 void VisibilityChanged(views::View* starting_from, bool is_visible) override; 131 int NonClientHitTest(const gfx::Point& point) override; 132 void ResetWindowControls() override; 133 web_app_frame_toolbar_for_testing()134 WebAppFrameToolbarView* web_app_frame_toolbar_for_testing() { 135 return web_app_frame_toolbar_; 136 } 137 138 protected: 139 // Called when |frame_|'s "paint as active" state has changed. 140 virtual void PaintAsActiveChanged(); 141 142 // Converts an ActiveState to a bool representing whether the frame should be 143 // treated as active. 144 bool ShouldPaintAsActive(BrowserFrameActiveState active_state) const; 145 146 // Compute aspects of the frame needed to paint the frame background. 147 gfx::ImageSkia GetFrameImage(BrowserFrameActiveState active_state = 148 BrowserFrameActiveState::kUseCurrent) const; 149 gfx::ImageSkia GetFrameOverlayImage( 150 BrowserFrameActiveState active_state = 151 BrowserFrameActiveState::kUseCurrent) const; 152 153 // views::NonClientFrameView: 154 void ChildPreferredSizeChanged(views::View* child) override; 155 bool DoesIntersectRect(const views::View* target, 156 const gfx::Rect& rect) const override; 157 158 // ProfileAttributesStorage::Observer: 159 void OnProfileAdded(const base::FilePath& profile_path) override; 160 void OnProfileWasRemoved(const base::FilePath& profile_path, 161 const base::string16& profile_name) override; 162 void OnProfileAvatarChanged(const base::FilePath& profile_path) override; 163 void OnProfileHighResAvatarLoaded( 164 const base::FilePath& profile_path) override; 165 set_web_app_frame_toolbar(WebAppFrameToolbarView * web_app_frame_toolbar)166 void set_web_app_frame_toolbar( 167 WebAppFrameToolbarView* web_app_frame_toolbar) { 168 web_app_frame_toolbar_ = web_app_frame_toolbar; 169 } web_app_frame_toolbar()170 WebAppFrameToolbarView* web_app_frame_toolbar() { 171 return web_app_frame_toolbar_; 172 } web_app_frame_toolbar()173 const WebAppFrameToolbarView* web_app_frame_toolbar() const { 174 return web_app_frame_toolbar_; 175 } 176 177 private: 178 // views::NonClientFrameView: 179 #if defined(OS_WIN) 180 int GetSystemMenuY() const override; 181 #endif 182 183 // Get the |frame_| theme provider since it should be non-null even before 184 // we're added to the view hierarchy. 185 const ui::ThemeProvider* GetFrameThemeProvider() const; 186 187 // The frame that hosts this view. 188 BrowserFrame* const frame_; 189 190 // The BrowserView hosted within this View. 191 BrowserView* const browser_view_; 192 193 // Menu button and page status icons. Only used by web-app windows. 194 WebAppFrameToolbarView* web_app_frame_toolbar_ = nullptr; 195 196 std::unique_ptr<views::Widget::PaintAsActiveCallbackList::Subscription> 197 paint_as_active_subscription_ = 198 frame_->RegisterPaintAsActiveChangedCallback(base::BindRepeating( 199 &BrowserNonClientFrameView::PaintAsActiveChanged, 200 base::Unretained(this))); 201 202 ScopedObserver<TabStrip, TabStripObserver> tab_strip_observer_{this}; 203 204 DISALLOW_COPY_AND_ASSIGN(BrowserNonClientFrameView); 205 }; 206 207 namespace chrome { 208 209 // Provided by a browser_non_client_frame_view_factory_*.cc implementation 210 std::unique_ptr<BrowserNonClientFrameView> CreateBrowserNonClientFrameView( 211 BrowserFrame* frame, 212 BrowserView* browser_view); 213 214 } // namespace chrome 215 216 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_NON_CLIENT_FRAME_VIEW_H_ 217