Home | History | Annotate | Download | only in views
      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 #include "chrome/browser/ui/views/wrench_toolbar_button.h"
      6 
      7 #include "grit/theme_resources.h"
      8 #include "ui/base/resource/resource_bundle.h"
      9 #include "ui/base/theme_provider.h"
     10 
     11 WrenchToolbarButton::WrenchToolbarButton(views::MenuButtonListener* listener)
     12     : views::MenuButton(NULL, string16(), listener, false) {
     13   wrench_icon_painter_.reset(new WrenchIconPainter(this));
     14 
     15   // Used for sizing only.
     16   ui::ResourceBundle& rb = ResourceBundle::GetSharedInstance();
     17   SetIcon(*rb.GetImageSkiaNamed(IDR_TOOLBAR_BEZEL_HOVER));
     18 }
     19 
     20 WrenchToolbarButton::~WrenchToolbarButton() {
     21 }
     22 
     23 void WrenchToolbarButton::SetSeverity(WrenchIconPainter::Severity severity,
     24                                       bool animate) {
     25   wrench_icon_painter_->SetSeverity(severity, animate);
     26 }
     27 
     28 void WrenchToolbarButton::OnPaint(gfx::Canvas* canvas) {
     29   // Badge non-ChromeOS ASH builds so that users know that they are using ASH.
     30 #if defined(USE_ASH) && !defined(OS_CHROMEOS)
     31   wrench_icon_painter_->set_badge(
     32       *GetThemeProvider()->GetImageSkiaNamed(IDR_TOOLS_BADGE_ASH));
     33 #endif
     34 
     35   wrench_icon_painter_->Paint(
     36       canvas, GetThemeProvider(), gfx::Rect(size()), GetCurrentBezelType());
     37 }
     38 
     39 void WrenchToolbarButton::ScheduleWrenchIconPaint() {
     40   SchedulePaint();
     41 }
     42 
     43 WrenchIconPainter::BezelType WrenchToolbarButton::GetCurrentBezelType() const {
     44   switch (state()) {
     45     case STATE_HOVERED:
     46       return WrenchIconPainter::BEZEL_HOVER;
     47     case STATE_PRESSED:
     48       return WrenchIconPainter::BEZEL_PRESSED;
     49     default:
     50       return WrenchIconPainter::BEZEL_NONE;
     51   }
     52 }
     53