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