• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2006-2008 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_TAB_ICON_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TAB_ICON_VIEW_H_
7 #pragma once
8 
9 #include "views/view.h"
10 
11 class SkBitmap;
12 class TabContents;
13 
14 ////////////////////////////////////////////////////////////////////////////////
15 //
16 // A view to display a tab favicon or a throbber.
17 //
18 ////////////////////////////////////////////////////////////////////////////////
19 class TabIconView : public views::View {
20  public:
21   // Classes implement this interface to provide state for the TabIconView.
22   class TabIconViewModel {
23    public:
24     // Returns true if the TabIconView should show a loading animation.
25     virtual bool ShouldTabIconViewAnimate() const = 0;
26 
27     // Returns the favicon to display in the icon view
28     virtual SkBitmap GetFaviconForTabIconView() = 0;
29   };
30 
31   static void InitializeIfNeeded();
32 
33   explicit TabIconView(TabIconViewModel* provider);
34   virtual ~TabIconView();
35 
36   // Invoke whenever the tab state changes or the throbber should update.
37   void Update();
38 
39   // Set the throbber to the light style (for use on dark backgrounds).
set_is_light(bool is_light)40   void set_is_light(bool is_light) { is_light_ = is_light; }
41 
42   // Overridden from View
43   virtual void OnPaint(gfx::Canvas* canvas);
44   virtual gfx::Size GetPreferredSize();
45 
46  private:
47   void PaintThrobber(gfx::Canvas* canvas);
48   void PaintFavicon(gfx::Canvas* canvas, const SkBitmap& bitmap);
49   void PaintIcon(gfx::Canvas* canvas,
50                  const SkBitmap& bitmap,
51                  int src_x,
52                  int src_y,
53                  int src_w,
54                  int src_h,
55                  bool filter);
56 
57   // Our model.
58   TabIconViewModel* model_;
59 
60   // Whether the throbber is running.
61   bool throbber_running_;
62 
63   // Whether we should display our light or dark style.
64   bool is_light_;
65 
66   // Current frame of the throbber being painted. This is only used if
67   // throbber_running_ is true.
68   int throbber_frame_;
69 
70   DISALLOW_COPY_AND_ASSIGN(TabIconView);
71 };
72 
73 #endif  // CHROME_BROWSER_UI_VIEWS_TAB_ICON_VIEW_H_
74