tab_icon_view.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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_TAB_ICON_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_TAB_ICON_VIEW_H_ 7 8#include "base/basictypes.h" 9#include "base/compiler_specific.h" 10#include "ui/views/controls/button/menu_button.h" 11#include "ui/views/view.h" 12 13namespace chrome { 14class TabIconViewModel; 15} 16 17namespace gfx { 18class ImageSkia; 19} 20 21// A view to display a tab favicon or a throbber. 22class TabIconView : public views::MenuButton { 23 public: 24 static void InitializeIfNeeded(); 25 26 TabIconView(chrome::TabIconViewModel* model, 27 views::MenuButtonListener* menu_button_listener); 28 virtual ~TabIconView(); 29 30 // Invoke whenever the tab state changes or the throbber should update. 31 void Update(); 32 33 // Set the throbber to the light style (for use on dark backgrounds). 34 void set_is_light(bool is_light) { is_light_ = is_light; } 35 36 // Overridden from View 37 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 38 virtual gfx::Size GetPreferredSize() const OVERRIDE; 39 40 private: 41 void PaintThrobber(gfx::Canvas* canvas); 42 void PaintFavicon(gfx::Canvas* canvas, const gfx::ImageSkia& image); 43 void PaintIcon(gfx::Canvas* canvas, 44 const gfx::ImageSkia& image, 45 int src_x, 46 int src_y, 47 int src_w, 48 int src_h, 49 bool filter); 50 51 // Our model. 52 chrome::TabIconViewModel* model_; 53 54 // Whether the throbber is running. 55 bool throbber_running_; 56 57 // Whether we should display our light or dark style. 58 bool is_light_; 59 60 // Current frame of the throbber being painted. This is only used if 61 // throbber_running_ is true. 62 int throbber_frame_; 63 64 DISALLOW_COPY_AND_ASSIGN(TabIconView); 65}; 66 67#endif // CHROME_BROWSER_UI_VIEWS_TAB_ICON_VIEW_H_ 68