Home | History | Annotate | Download | only in frame
      1 // Copyright (c) 2011 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 #pragma once
      8 
      9 #include "chrome/browser/ui/views/frame/browser_frame.h"
     10 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
     11 #include "chrome/browser/ui/views/tab_icon_view.h"
     12 #include "views/controls/button/button.h"
     13 #include "views/window/non_client_view.h"
     14 
     15 class BrowserView;
     16 namespace gfx {
     17 class Font;
     18 }
     19 class TabContents;
     20 namespace views {
     21 class ImageButton;
     22 class ImageView;
     23 }
     24 
     25 class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
     26                                public views::ButtonListener,
     27                                public TabIconView::TabIconViewModel {
     28  public:
     29   // Constructs a non-client view for an BrowserFrame.
     30   OpaqueBrowserFrameView(BrowserFrame* frame, BrowserView* browser_view);
     31   virtual ~OpaqueBrowserFrameView();
     32 
     33   // Overridden from BrowserNonClientFrameView:
     34   virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const OVERRIDE;
     35   virtual int GetHorizontalTabStripVerticalOffset(bool restored) const OVERRIDE;
     36   virtual void UpdateThrobber(bool running) OVERRIDE;
     37   virtual gfx::Size GetMinimumSize() OVERRIDE;
     38 
     39  protected:
     40   BrowserView* browser_view() const { return browser_view_; }
     41   views::ImageButton* minimize_button() const { return minimize_button_; }
     42   views::ImageButton* maximize_button() const { return maximize_button_; }
     43   views::ImageButton* restore_button() const { return restore_button_; }
     44   views::ImageButton* close_button() const { return close_button_; }
     45 
     46   // Used to allow subclasses to reserve height for other components they
     47   // will add.  The space is reserved below the ClientView.
     48   virtual int GetReservedHeight() const;
     49   virtual gfx::Rect GetBoundsForReservedArea() const;
     50 
     51   // Returns the height of the entire nonclient top border, including the window
     52   // frame, any title area, and any connected client edge.  If |restored| is
     53   // true, acts as if the window is restored regardless of the real mode.  If
     54   // |ignore_vertical_tabs| is true, acts as if vertical tabs are off regardless
     55   // of the real state.
     56   int NonClientTopBorderHeight(bool restored, bool ignore_vertical_tabs) const;
     57 
     58   // Allows a subclass to tweak the frame. Chromeos uses this to support
     59   // drawing themes correctly. |theme_offset| is used to adjust the y offset
     60   // of the theme frame bitmap, so they start at the right location.
     61   // |left_corner| and |right_corner| will be used on the left and right of
     62   // the tabstrip area as opposed to the theme frame.
     63   virtual void ModifyMaximizedFramePainting(
     64       int* theme_offset,
     65       SkBitmap** left_corner,
     66       SkBitmap** right_corner);
     67 
     68   // Expose these to subclasses.
     69   BrowserFrame* frame() { return frame_; }
     70   BrowserView* browser_view() { return browser_view_; }
     71 
     72   // Overridden from views::NonClientFrameView:
     73   virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
     74   virtual bool AlwaysUseNativeFrame() const OVERRIDE;
     75   virtual bool AlwaysUseCustomFrame() const OVERRIDE;
     76   virtual gfx::Rect GetWindowBoundsForClientBounds(
     77       const gfx::Rect& client_bounds) const OVERRIDE;
     78   virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
     79   virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask)
     80       OVERRIDE;
     81   virtual void EnableClose(bool enable) OVERRIDE;
     82   virtual void ResetWindowControls() OVERRIDE;
     83   virtual void UpdateWindowIcon() OVERRIDE;
     84 
     85   // Overridden from views::View:
     86   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     87   virtual void Layout() OVERRIDE;
     88   virtual bool HitTest(const gfx::Point& l) const OVERRIDE;
     89   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
     90 
     91   // Overridden from views::ButtonListener:
     92   virtual void ButtonPressed(views::Button* sender, const views::Event& event)
     93       OVERRIDE;
     94 
     95   // Overridden from TabIconView::TabIconViewModel:
     96   virtual bool ShouldTabIconViewAnimate() const OVERRIDE;
     97   virtual SkBitmap GetFaviconForTabIconView() OVERRIDE;
     98 
     99  private:
    100   // Returns the thickness of the border that makes up the window frame edges.
    101   // This does not include any client edge.  If |restored| is true, acts as if
    102   // the window is restored regardless of the real mode.
    103   int FrameBorderThickness(bool restored) const;
    104 
    105   // Returns the height of the top resize area.  This is smaller than the frame
    106   // border height in order to increase the window draggable area.
    107   int TopResizeHeight() const;
    108 
    109   // Returns the thickness of the entire nonclient left, right, and bottom
    110   // borders, including both the window frame and any client edge.
    111   int NonClientBorderThickness() const;
    112 
    113   // Returns the y-coordinate of the caption buttons.  If |restored| is true,
    114   // acts as if the window is restored regardless of the real mode.
    115   int CaptionButtonY(bool restored) const;
    116 
    117   // Returns the thickness of the 3D edge along the bottom of the titlebar.  If
    118   // |restored| is true, acts as if the window is restored regardless of the
    119   // real mode.
    120   int TitlebarBottomThickness(bool restored) const;
    121 
    122   // Returns the size of the titlebar icon.  This is used even when the icon is
    123   // not shown, e.g. to set the titlebar height.
    124   int IconSize() const;
    125 
    126   // Returns the bounds of the titlebar icon (or where the icon would be if
    127   // there was one).
    128   gfx::Rect IconBounds() const;
    129 
    130   // Paint various sub-components of this view.  The *FrameBorder() functions
    131   // also paint the background of the titlebar area, since the top frame border
    132   // and titlebar background are a contiguous component.
    133   void PaintRestoredFrameBorder(gfx::Canvas* canvas);
    134   void PaintMaximizedFrameBorder(gfx::Canvas* canvas);
    135   void PaintTitleBar(gfx::Canvas* canvas);
    136   void PaintToolbarBackground(gfx::Canvas* canvas);
    137   void PaintOTRAvatar(gfx::Canvas* canvas);
    138   void PaintRestoredClientEdge(gfx::Canvas* canvas);
    139 
    140   // Layout various sub-components of this view.
    141   void LayoutWindowControls();
    142   void LayoutTitleBar();
    143   void LayoutOTRAvatar();
    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   // The layout rect of the title, if visible.
    149   gfx::Rect title_bounds_;
    150 
    151   // The layout rect of the OTR avatar icon, if visible.
    152   gfx::Rect otr_avatar_bounds_;
    153 
    154   // Window controls.
    155   views::ImageButton* minimize_button_;
    156   views::ImageButton* maximize_button_;
    157   views::ImageButton* restore_button_;
    158   views::ImageButton* close_button_;
    159 
    160   // The Window icon.
    161   TabIconView* window_icon_;
    162 
    163   // The frame that hosts this view.
    164   BrowserFrame* frame_;
    165 
    166   // The BrowserView hosted within this View.
    167   BrowserView* browser_view_;
    168 
    169   // The bounds of the ClientView.
    170   gfx::Rect client_view_bounds_;
    171 
    172   DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameView);
    173 };
    174 
    175 #endif  // CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_H_
    176