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