Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/browser/ui/views/location_bar/search_button.cc

Issue 371633002: LabelButton: cache the last computed preferred size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/location_bar/search_button.h" 5 #include "chrome/browser/ui/views/location_bar/search_button.h"
6 6
7 #include "grit/theme_resources.h" 7 #include "grit/theme_resources.h"
8 #include "ui/base/theme_provider.h" 8 #include "ui/base/theme_provider.h"
9 #include "ui/views/controls/button/label_button_border.h" 9 #include "ui/views/controls/button/label_button_border.h"
10 10
11 SearchButton::SearchButton(views::ButtonListener* listener) 11 SearchButton::SearchButton(views::ButtonListener* listener)
12 : views::LabelButton(listener, base::string16()) { 12 : views::LabelButton(listener, base::string16()) {
13 EnableCanvasFlippingForRTLUI(true); 13 EnableCanvasFlippingForRTLUI(true);
14 set_triggerable_event_flags( 14 set_triggerable_event_flags(
15 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); 15 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON);
16 SetStyle(views::Button::STYLE_BUTTON); 16 SetStyle(views::Button::STYLE_BUTTON);
17 SetFocusable(false); 17 SetFocusable(false);
18 set_min_size(gfx::Size()); 18 SetMinSize(gfx::Size());
19 scoped_ptr<views::LabelButtonBorder> border( 19 scoped_ptr<views::LabelButtonBorder> border(
20 new views::LabelButtonBorder(style())); 20 new views::LabelButtonBorder(style()));
21 border->set_insets(gfx::Insets()); 21 border->set_insets(gfx::Insets());
22 const int kSearchButtonNormalImages[] = IMAGE_GRID(IDR_OMNIBOX_SEARCH_BUTTON); 22 const int kSearchButtonNormalImages[] = IMAGE_GRID(IDR_OMNIBOX_SEARCH_BUTTON);
23 border->SetPainter( 23 border->SetPainter(
24 false, views::Button::STATE_NORMAL, 24 false, views::Button::STATE_NORMAL,
25 views::Painter::CreateImageGridPainter(kSearchButtonNormalImages)); 25 views::Painter::CreateImageGridPainter(kSearchButtonNormalImages));
26 const int kSearchButtonHoveredImages[] = 26 const int kSearchButtonHoveredImages[] =
27 IMAGE_GRID(IDR_OMNIBOX_SEARCH_BUTTON_HOVER); 27 IMAGE_GRID(IDR_OMNIBOX_SEARCH_BUTTON_HOVER);
28 border->SetPainter( 28 border->SetPainter(
29 false, views::Button::STATE_HOVERED, 29 false, views::Button::STATE_HOVERED,
30 views::Painter::CreateImageGridPainter(kSearchButtonHoveredImages)); 30 views::Painter::CreateImageGridPainter(kSearchButtonHoveredImages));
31 const int kSearchButtonPressedImages[] = 31 const int kSearchButtonPressedImages[] =
32 IMAGE_GRID(IDR_OMNIBOX_SEARCH_BUTTON_PRESSED); 32 IMAGE_GRID(IDR_OMNIBOX_SEARCH_BUTTON_PRESSED);
33 border->SetPainter( 33 border->SetPainter(
34 false, views::Button::STATE_PRESSED, 34 false, views::Button::STATE_PRESSED,
35 views::Painter::CreateImageGridPainter(kSearchButtonPressedImages)); 35 views::Painter::CreateImageGridPainter(kSearchButtonPressedImages));
36 border->SetPainter(false, views::Button::STATE_DISABLED, NULL); 36 border->SetPainter(false, views::Button::STATE_DISABLED, NULL);
37 border->SetPainter(true, views::Button::STATE_NORMAL, NULL); 37 border->SetPainter(true, views::Button::STATE_NORMAL, NULL);
38 border->SetPainter(true, views::Button::STATE_HOVERED, NULL); 38 border->SetPainter(true, views::Button::STATE_HOVERED, NULL);
39 border->SetPainter(true, views::Button::STATE_PRESSED, NULL); 39 border->SetPainter(true, views::Button::STATE_PRESSED, NULL);
40 border->SetPainter(true, views::Button::STATE_DISABLED, NULL); 40 border->SetPainter(true, views::Button::STATE_DISABLED, NULL);
41 SetBorder(border.PassAs<views::Border>()); 41 SetBorder(border.PassAs<views::Border>());
42 const int kSearchButtonWidth = 56; 42 const int kSearchButtonWidth = 56;
43 set_min_size(gfx::Size(kSearchButtonWidth, 0)); 43 SetMinSize(gfx::Size(kSearchButtonWidth, 0));
44 } 44 }
45 45
46 SearchButton::~SearchButton() { 46 SearchButton::~SearchButton() {
47 } 47 }
48 48
49 void SearchButton::UpdateIcon(bool is_search) { 49 void SearchButton::UpdateIcon(bool is_search) {
50 SetImage( 50 SetImage(
51 views::Button::STATE_NORMAL, 51 views::Button::STATE_NORMAL,
52 *GetThemeProvider()->GetImageSkiaNamed(is_search ? 52 *GetThemeProvider()->GetImageSkiaNamed(is_search ?
53 IDR_OMNIBOX_SEARCH_BUTTON_LOUPE : IDR_OMNIBOX_SEARCH_BUTTON_ARROW)); 53 IDR_OMNIBOX_SEARCH_BUTTON_LOUPE : IDR_OMNIBOX_SEARCH_BUTTON_ARROW));
54 // Flip the arrow for RTL, but not the loupe. 54 // Flip the arrow for RTL, but not the loupe.
55 image()->EnableCanvasFlippingForRTLUI(!is_search); 55 image()->EnableCanvasFlippingForRTLUI(!is_search);
56 } 56 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/fullscreen_exit_bubble_views.cc ('k') | chrome/browser/ui/views/profiles/new_avatar_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698