opaque_browser_frame_view.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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_OPAQUE_BROWSER_FRAME_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_H_ 7 8#include "base/memory/scoped_ptr.h" 9#include "chrome/browser/ui/view_ids.h" 10#include "chrome/browser/ui/views/frame/browser_frame.h" 11#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h" 12#include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout_delegate.h" 13#include "chrome/browser/ui/views/tab_icon_view_model.h" 14#include "content/public/browser/notification_observer.h" 15#include "content/public/browser/notification_registrar.h" 16#include "ui/views/controls/button/button.h" 17#include "ui/views/controls/button/menu_button_listener.h" 18#include "ui/views/window/non_client_view.h" 19 20class BrowserView; 21class OpaqueBrowserFrameViewLayout; 22class OpaqueBrowserFrameViewPlatformSpecific; 23class TabIconView; 24class NewAvatarButton; 25 26namespace views { 27class ImageButton; 28class FrameBackground; 29class Label; 30} 31 32class OpaqueBrowserFrameView : public BrowserNonClientFrameView, 33 public content::NotificationObserver, 34 public views::ButtonListener, 35 public views::MenuButtonListener, 36 public chrome::TabIconViewModel, 37 public OpaqueBrowserFrameViewLayoutDelegate { 38 public: 39 // Constructs a non-client view for an BrowserFrame. 40 OpaqueBrowserFrameView(BrowserFrame* frame, BrowserView* browser_view); 41 virtual ~OpaqueBrowserFrameView(); 42 43 // Overridden from BrowserNonClientFrameView: 44 virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const OVERRIDE; 45 virtual int GetTopInset() const OVERRIDE; 46 virtual int GetThemeBackgroundXInset() const OVERRIDE; 47 virtual void UpdateThrobber(bool running) OVERRIDE; 48 virtual gfx::Size GetMinimumSize() OVERRIDE; 49 50 // Overridden from views::NonClientFrameView: 51 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; 52 virtual gfx::Rect GetWindowBoundsForClientBounds( 53 const gfx::Rect& client_bounds) const OVERRIDE; 54 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; 55 virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) 56 OVERRIDE; 57 virtual void ResetWindowControls() OVERRIDE; 58 virtual void UpdateWindowIcon() OVERRIDE; 59 virtual void UpdateWindowTitle() OVERRIDE; 60 61 // Overridden from views::View: 62 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE; 63 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; 64 65 // Overridden from views::ButtonListener: 66 virtual void ButtonPressed(views::Button* sender, const ui::Event& event) 67 OVERRIDE; 68 69 // Overridden from views::MenuButtonListener: 70 virtual void OnMenuButtonClicked(views::View* source, const gfx::Point& point) 71 OVERRIDE; 72 73 // Overridden from chrome::TabIconViewModel: 74 virtual bool ShouldTabIconViewAnimate() const OVERRIDE; 75 virtual gfx::ImageSkia GetFaviconForTabIconView() OVERRIDE; 76 77 // content::NotificationObserver implementation: 78 virtual void Observe(int type, 79 const content::NotificationSource& source, 80 const content::NotificationDetails& details) OVERRIDE; 81 82 // OpaqueBrowserFrameViewLayoutDelegate implementation: 83 virtual bool ShouldShowWindowIcon() const OVERRIDE; 84 virtual bool ShouldShowWindowTitle() const OVERRIDE; 85 virtual base::string16 GetWindowTitle() const OVERRIDE; 86 virtual int GetIconSize() const OVERRIDE; 87 virtual bool ShouldLeaveOffsetNearTopBorder() const OVERRIDE; 88 virtual gfx::Size GetBrowserViewMinimumSize() const OVERRIDE; 89 virtual bool ShouldShowCaptionButtons() const OVERRIDE; 90 virtual bool ShouldShowAvatar() const OVERRIDE; 91 virtual bool IsRegularOrGuestSession() const OVERRIDE; 92 virtual gfx::ImageSkia GetOTRAvatarIcon() const OVERRIDE; 93 virtual bool IsMaximized() const OVERRIDE; 94 virtual bool IsMinimized() const OVERRIDE; 95 virtual bool IsFullscreen() const OVERRIDE; 96 virtual bool IsTabStripVisible() const OVERRIDE; 97 virtual int GetTabStripHeight() const OVERRIDE; 98 virtual int GetAdditionalReservedSpaceInTabStrip() const OVERRIDE; 99 virtual gfx::Size GetTabstripPreferredSize() const OVERRIDE; 100 101 protected: 102 views::ImageButton* minimize_button() const { return minimize_button_; } 103 views::ImageButton* maximize_button() const { return maximize_button_; } 104 views::ImageButton* restore_button() const { return restore_button_; } 105 views::ImageButton* close_button() const { return close_button_; } 106 107 // Overridden from views::View: 108 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 109 110 private: 111 // Creates, adds and returns a new image button with |this| as its listener. 112 // Memory is owned by the caller. 113 views::ImageButton* InitWindowCaptionButton(int normal_image_id, 114 int hot_image_id, 115 int pushed_image_id, 116 int mask_image_id, 117 int accessibility_string_id, 118 ViewID view_id); 119 120 // Returns the thickness of the border that makes up the window frame edges. 121 // This does not include any client edge. If |restored| is true, acts as if 122 // the window is restored regardless of the real mode. 123 int FrameBorderThickness(bool restored) const; 124 125 // Returns the height of the top resize area. This is smaller than the frame 126 // border height in order to increase the window draggable area. 127 int TopResizeHeight() const; 128 129 // Returns the thickness of the entire nonclient left, right, and bottom 130 // borders, including both the window frame and any client edge. 131 int NonClientBorderThickness() const; 132 133 // Returns the bounds of the titlebar icon (or where the icon would be if 134 // there was one). 135 gfx::Rect IconBounds() const; 136 137 // Returns true if the view should draw its own custom title bar. 138 bool ShouldShowWindowTitleBar() const; 139 140 // Paint various sub-components of this view. The *FrameBorder() functions 141 // also paint the background of the titlebar area, since the top frame border 142 // and titlebar background are a contiguous component. 143 void PaintRestoredFrameBorder(gfx::Canvas* canvas); 144 void PaintMaximizedFrameBorder(gfx::Canvas* canvas); 145 void PaintToolbarBackground(gfx::Canvas* canvas); 146 void PaintRestoredClientEdge(gfx::Canvas* canvas); 147 148 // Compute aspects of the frame needed to paint the frame background. 149 SkColor GetFrameColor() const; 150 gfx::ImageSkia* GetFrameImage() const; 151 gfx::ImageSkia* GetFrameOverlayImage() const; 152 int GetTopAreaHeight() const; 153 154 // Returns the bounds of the client area for the specified view size. 155 gfx::Rect CalculateClientAreaBounds(int width, int height) const; 156 157 // Our layout manager also calculates various bounds. 158 OpaqueBrowserFrameViewLayout* layout_; 159 160 // Window controls. 161 views::ImageButton* minimize_button_; 162 views::ImageButton* maximize_button_; 163 views::ImageButton* restore_button_; 164 views::ImageButton* close_button_; 165 166 // The window icon and title. 167 TabIconView* window_icon_; 168 views::Label* window_title_; 169 170 content::NotificationRegistrar registrar_; 171 172 // Background painter for the window frame. 173 scoped_ptr<views::FrameBackground> frame_background_; 174 175 // Observer that handles platform dependent configuration. 176 scoped_ptr<OpaqueBrowserFrameViewPlatformSpecific> platform_observer_; 177 178 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameView); 179}; 180 181#endif // CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_H_ 182