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_GLASS_BROWSER_FRAME_VIEW_H_
      6 #define CHROME_BROWSER_UI_VIEWS_FRAME_GLASS_BROWSER_FRAME_VIEW_H_
      7 #pragma once
      8 
      9 #include "base/memory/scoped_ptr.h"
     10 #include "chrome/browser/prefs/pref_member.h"
     11 #include "chrome/browser/ui/views/frame/browser_frame_win.h"
     12 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
     13 #include "views/controls/button/button.h"
     14 #include "views/controls/menu/view_menu_delegate.h"
     15 #include "views/window/non_client_view.h"
     16 
     17 class BrowserView;
     18 class SkBitmap;
     19 
     20 namespace views {
     21 class ProfileMenuButton;
     22 class ProfileMenuModel;
     23 class ProfileTagView;
     24 }
     25 
     26 class GlassBrowserFrameView : public BrowserNonClientFrameView,
     27                               public NotificationObserver,
     28                               public views::ViewMenuDelegate {
     29  public:
     30   // Constructs a non-client view for an BrowserFrame.
     31   GlassBrowserFrameView(BrowserFrame* frame, BrowserView* browser_view);
     32   virtual ~GlassBrowserFrameView();
     33 
     34   // Overridden from BrowserNonClientFrameView:
     35   virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const OVERRIDE;
     36   virtual int GetHorizontalTabStripVerticalOffset(bool restored) const OVERRIDE;
     37   virtual void UpdateThrobber(bool running) OVERRIDE;
     38 
     39   // Overridden from views::NonClientFrameView:
     40   virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
     41   virtual bool AlwaysUseNativeFrame() const OVERRIDE;
     42   virtual gfx::Rect GetWindowBoundsForClientBounds(
     43       const gfx::Rect& client_bounds) const OVERRIDE;
     44   virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
     45   virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask)
     46       OVERRIDE { }
     47   virtual void EnableClose(bool enable) OVERRIDE { }
     48   virtual void ResetWindowControls() OVERRIDE { }
     49   virtual void UpdateWindowIcon() OVERRIDE { }
     50 
     51   // views::ViewMenuDelegate implementation:
     52   virtual void RunMenu(views::View* source, const gfx::Point& pt) OVERRIDE;
     53 
     54  protected:
     55   // Overridden from views::View:
     56   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     57   virtual void Layout() OVERRIDE;
     58   virtual bool HitTest(const gfx::Point& l) const OVERRIDE;
     59 
     60  private:
     61   // Returns the thickness of the border that makes up the window frame edges.
     62   // This does not include any client edge.
     63   int FrameBorderThickness() const;
     64 
     65   // Returns the thickness of the entire nonclient left, right, and bottom
     66   // borders, including both the window frame and any client edge.
     67   int NonClientBorderThickness() const;
     68 
     69   // Returns the height of the entire nonclient top border, including the window
     70   // frame, any title area, and any connected client edge.  If |restored| is
     71   // true, acts as if the window is restored regardless of the real mode.  If
     72   // |ignore_vertical_tabs| is true, acts as if vertical tabs are off regardless
     73   // of the real state.
     74   int NonClientTopBorderHeight(bool restored, bool ignore_vertical_tabs) const;
     75 
     76   // Paint various sub-components of this view.
     77   void PaintToolbarBackground(gfx::Canvas* canvas);
     78   void PaintOTRAvatar(gfx::Canvas* canvas);
     79   void PaintRestoredClientEdge(gfx::Canvas* canvas);
     80 
     81   // Layout various sub-components of this view.
     82   void LayoutOTRAvatar();
     83   void LayoutClientView();
     84   void LayoutProfileTag();
     85 
     86   // Returns the bounds of the client area for the specified view size.
     87   gfx::Rect CalculateClientAreaBounds(int width, int height) const;
     88 
     89   // Starts/Stops the window throbber running.
     90   void StartThrobber();
     91   void StopThrobber();
     92 
     93   // Displays the next throbber frame.
     94   void DisplayNextThrobberFrame();
     95 
     96   // NotificationObserver implementation:
     97   virtual void Observe(NotificationType type,
     98                        const NotificationSource& source,
     99                        const NotificationDetails& details) OVERRIDE;
    100 
    101   // Receive notifications when the user's Google services user name changes.
    102   void RegisterLoginNotifications();
    103 
    104   // Returns true if the ProfileButton has been created.
    105   bool show_profile_button() const { return profile_button_.get() != NULL; }
    106 
    107   // The layout rect of the OTR avatar icon, if visible.
    108   gfx::Rect otr_avatar_bounds_;
    109 
    110   // The frame that hosts this view.
    111   BrowserFrame* frame_;
    112 
    113   // The BrowserView hosted within this View.
    114   BrowserView* browser_view_;
    115 
    116   // The bounds of the ClientView.
    117   gfx::Rect client_view_bounds_;
    118 
    119   // Menu button that displays user's name and multi-profile menu.
    120   scoped_ptr<views::ProfileMenuButton> profile_button_;
    121 
    122   // Image tag displayed on frame beneath profile_button_.
    123   scoped_ptr<views::ProfileTagView> profile_tag_;
    124 
    125   // Multi-profile menu for profile_button_.
    126   scoped_ptr<views::ProfileMenuModel> profile_menu_model_;
    127 
    128   // Whether or not the window throbber is currently animating.
    129   bool throbber_running_;
    130 
    131   // The index of the current frame of the throbber animation.
    132   int throbber_frame_;
    133 
    134   // The Google services user name associated with this BrowserView's profile.
    135   StringPrefMember username_pref_;
    136 
    137   static const int kThrobberIconCount = 24;
    138   static HICON throbber_icons_[kThrobberIconCount];
    139   static void InitThrobberIcons();
    140 
    141   DISALLOW_COPY_AND_ASSIGN(GlassBrowserFrameView);
    142 };
    143 
    144 #endif  // CHROME_BROWSER_UI_VIEWS_FRAME_GLASS_BROWSER_FRAME_VIEW_H_
    145