1 // Copyright 2014 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/location_bar/search_button.h" 6 7 #include "grit/theme_resources.h" 8 #include "ui/base/theme_provider.h" 9 #include "ui/views/controls/button/label_button_border.h" 10 11 SearchButton::SearchButton(views::ButtonListener* listener) 12 : views::LabelButton(listener, base::string16()) { 13 EnableCanvasFlippingForRTLUI(true); 14 set_triggerable_event_flags( 15 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); 16 SetStyle(views::Button::STYLE_BUTTON); 17 SetFocusable(false); 18 SetMinSize(gfx::Size()); 19 scoped_ptr<views::LabelButtonBorder> border( 20 new views::LabelButtonBorder(style())); 21 border->set_insets(gfx::Insets()); 22 const int kSearchButtonNormalImages[] = IMAGE_GRID(IDR_OMNIBOX_SEARCH_BUTTON); 23 border->SetPainter( 24 false, views::Button::STATE_NORMAL, 25 views::Painter::CreateImageGridPainter(kSearchButtonNormalImages)); 26 const int kSearchButtonHoveredImages[] = 27 IMAGE_GRID(IDR_OMNIBOX_SEARCH_BUTTON_HOVER); 28 border->SetPainter( 29 false, views::Button::STATE_HOVERED, 30 views::Painter::CreateImageGridPainter(kSearchButtonHoveredImages)); 31 const int kSearchButtonPressedImages[] = 32 IMAGE_GRID(IDR_OMNIBOX_SEARCH_BUTTON_PRESSED); 33 border->SetPainter( 34 false, views::Button::STATE_PRESSED, 35 views::Painter::CreateImageGridPainter(kSearchButtonPressedImages)); 36 border->SetPainter(false, views::Button::STATE_DISABLED, NULL); 37 border->SetPainter(true, views::Button::STATE_NORMAL, NULL); 38 border->SetPainter(true, views::Button::STATE_HOVERED, NULL); 39 border->SetPainter(true, views::Button::STATE_PRESSED, NULL); 40 border->SetPainter(true, views::Button::STATE_DISABLED, NULL); 41 SetBorder(border.PassAs<views::Border>()); 42 const int kSearchButtonWidth = 56; 43 SetMinSize(gfx::Size(kSearchButtonWidth, 0)); 44 } 45 46 SearchButton::~SearchButton() { 47 } 48 49 void SearchButton::UpdateIcon(bool is_search) { 50 SetImage( 51 views::Button::STATE_NORMAL, 52 *GetThemeProvider()->GetImageSkiaNamed(is_search ? 53 IDR_OMNIBOX_SEARCH_BUTTON_LOUPE : IDR_OMNIBOX_SEARCH_BUTTON_ARROW)); 54 // Flip the arrow for RTL, but not the loupe. 55 image()->EnableCanvasFlippingForRTLUI(!is_search); 56 } 57