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

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_action_view.cc

Issue 1214243003: [Extensions UI] Clean up extension icon generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/toolbar/toolbar_action_view.h" 5 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 16 matching lines...) Expand all
27 #include "ui/resources/grit/ui_resources.h" 27 #include "ui/resources/grit/ui_resources.h"
28 #include "ui/views/controls/button/label_button_border.h" 28 #include "ui/views/controls/button/label_button_border.h"
29 #include "ui/views/controls/menu/menu_controller.h" 29 #include "ui/views/controls/menu/menu_controller.h"
30 #include "ui/views/controls/menu/menu_runner.h" 30 #include "ui/views/controls/menu/menu_runner.h"
31 #include "ui/views/resources/grit/views_resources.h" 31 #include "ui/views/resources/grit/views_resources.h"
32 32
33 using views::LabelButtonBorder; 33 using views::LabelButtonBorder;
34 34
35 namespace { 35 namespace {
36 36
37 // We have smaller insets than normal STYLE_TEXTBUTTON buttons so that we can 37 // Toolbar action buttons have no insets because the badges are drawn right at
38 // fit user supplied icons in without clipping them. 38 // the edge of the view's area. Other badding (such as centering the icon) is
39 const int kBorderInset = 4; 39 // handled directly by the Image.
40 const int kBorderInset = 0;
Finnur 2015/07/06 10:27:09 nit: Is the inset not 0 by default?
Devlin 2015/07/06 19:16:07 Not for a LabelButtonBorder, no - it's all handled
40 41
41 // The ToolbarActionView which is currently showing its context menu, if any. 42 // The ToolbarActionView which is currently showing its context menu, if any.
42 // Since only one context menu can be shown (even across browser windows), it's 43 // Since only one context menu can be shown (even across browser windows), it's
43 // safe to have this be a global singleton. 44 // safe to have this be a global singleton.
44 ToolbarActionView* context_menu_owner = nullptr; 45 ToolbarActionView* context_menu_owner = nullptr;
45 46
46 } // namespace 47 } // namespace
47 48
48 //////////////////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////////////////
49 // ToolbarActionView 50 // ToolbarActionView
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 void ToolbarActionView::ViewHierarchyChanged( 116 void ToolbarActionView::ViewHierarchyChanged(
116 const ViewHierarchyChangedDetails& details) { 117 const ViewHierarchyChangedDetails& details) {
117 if (details.is_add && !called_register_command_ && GetFocusManager()) { 118 if (details.is_add && !called_register_command_ && GetFocusManager()) {
118 view_controller_->RegisterCommand(); 119 view_controller_->RegisterCommand();
119 called_register_command_ = true; 120 called_register_command_ = true;
120 } 121 }
121 122
122 MenuButton::ViewHierarchyChanged(details); 123 MenuButton::ViewHierarchyChanged(details);
123 } 124 }
124 125
125 void ToolbarActionView::PaintChildren(const ui::PaintContext& context) {
126 View::PaintChildren(context);
127 ui::PaintRecorder recorder(context);
128 view_controller_->PaintExtra(recorder.canvas(), GetLocalBounds(),
129 GetCurrentWebContents());
130 }
131
132 void ToolbarActionView::OnPaintBorder(gfx::Canvas* canvas) { 126 void ToolbarActionView::OnPaintBorder(gfx::Canvas* canvas) {
133 if (!wants_to_run_) 127 if (!wants_to_run_)
134 views::MenuButton::OnPaintBorder(canvas); 128 views::MenuButton::OnPaintBorder(canvas);
135 else 129 else
136 wants_to_run_border_->Paint(*this, canvas); 130 wants_to_run_border_->Paint(*this, canvas);
137 } 131 }
138 132
139 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { 133 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) {
140 views::MenuButton::GetAccessibleState(state); 134 views::MenuButton::GetAccessibleState(state);
141 state->role = ui::AX_ROLE_BUTTON; 135 state->role = ui::AX_ROLE_BUTTON;
142 } 136 }
143 137
144 void ToolbarActionView::ButtonPressed(views::Button* sender, 138 void ToolbarActionView::ButtonPressed(views::Button* sender,
145 const ui::Event& event) { 139 const ui::Event& event) {
146 view_controller_->ExecuteAction(true); 140 view_controller_->ExecuteAction(true);
147 } 141 }
148 142
149 void ToolbarActionView::UpdateState() { 143 void ToolbarActionView::UpdateState() {
150 content::WebContents* web_contents = GetCurrentWebContents(); 144 content::WebContents* web_contents = GetCurrentWebContents();
151 if (SessionTabHelper::IdForTab(web_contents) < 0) 145 if (SessionTabHelper::IdForTab(web_contents) < 0)
152 return; 146 return;
153 147
154 if (!view_controller_->IsEnabled(web_contents)) 148 if (!view_controller_->IsEnabled(web_contents))
155 SetState(views::CustomButton::STATE_DISABLED); 149 SetState(views::CustomButton::STATE_DISABLED);
156 else if (state() == views::CustomButton::STATE_DISABLED) 150 else if (state() == views::CustomButton::STATE_DISABLED)
157 SetState(views::CustomButton::STATE_NORMAL); 151 SetState(views::CustomButton::STATE_NORMAL);
158 152
159 wants_to_run_ = view_controller_->WantsToRun(web_contents); 153 wants_to_run_ = view_controller_->WantsToRun(web_contents);
160 154
161 gfx::ImageSkia icon(view_controller_->GetIcon(web_contents).AsImageSkia()); 155 gfx::ImageSkia icon(
156 view_controller_->GetIcon(web_contents,
157 GetPreferredSize()).AsImageSkia());
162 158
163 if (!icon.isNull()) { 159 if (!icon.isNull()) {
164 ThemeService* theme = ThemeServiceFactory::GetForProfile(profile_); 160 ThemeService* theme = ThemeServiceFactory::GetForProfile(profile_);
165 161
166 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION); 162 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION);
167 SetImage(views::Button::STATE_NORMAL, 163 SetImage(views::Button::STATE_NORMAL,
168 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); 164 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon));
169 } 165 }
170 166
171 SetTooltipText(view_controller_->GetTooltip(web_contents)); 167 SetTooltipText(view_controller_->GetTooltip(web_contents));
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 if (menu_controller->in_nested_run()) { 374 if (menu_controller->in_nested_run()) {
379 // There is another menu showing. Close the outermost menu (since we are 375 // There is another menu showing. Close the outermost menu (since we are
380 // shown in the same menu, we don't want to close the whole thing). 376 // shown in the same menu, we don't want to close the whole thing).
381 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); 377 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST);
382 return true; 378 return true;
383 } 379 }
384 } 380 }
385 381
386 return false; 382 return false;
387 } 383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698