Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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/app_menu_button.h" | 5 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 
| 6 | 6 | 
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" | 
| 8 #include "base/location.h" | 8 #include "base/location.h" | 
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" | 
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" | 
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" | 
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" | 
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" | 
| 14 #include "cc/paint/paint_flags.h" | 14 #include "cc/paint/paint_flags.h" | 
| 15 #include "chrome/app/vector_icons/vector_icons.h" | 15 #include "chrome/app/vector_icons/vector_icons.h" | 
| 16 #include "chrome/browser/themes/theme_properties.h" | 16 #include "chrome/browser/themes/theme_properties.h" | 
| 17 #include "chrome/browser/themes/theme_service.h" | |
| 18 #include "chrome/browser/themes/theme_service_factory.h" | |
| 17 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" | 
| 18 #include "chrome/browser/ui/browser_otr_state.h" | 20 #include "chrome/browser/ui/browser_otr_state.h" | 
| 19 #include "chrome/browser/ui/layout_constants.h" | 21 #include "chrome/browser/ui/layout_constants.h" | 
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 
| 21 #include "chrome/browser/ui/toolbar/app_menu_animation.h" | |
| 22 #include "chrome/browser/ui/toolbar/app_menu_model.h" | 23 #include "chrome/browser/ui/toolbar/app_menu_model.h" | 
| 23 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 24 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 
| 24 #include "chrome/browser/ui/views/toolbar/app_menu.h" | 25 #include "chrome/browser/ui/views/toolbar/app_menu.h" | 
| 25 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" | 26 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" | 
| 26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 27 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 
| 27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" | 
| 28 #include "chrome/grit/theme_resources.h" | 29 #include "chrome/grit/theme_resources.h" | 
| 29 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" | 
| 30 #include "ui/base/theme_provider.h" | 31 #include "ui/base/theme_provider.h" | 
| 31 #include "ui/gfx/canvas.h" | 32 #include "ui/gfx/canvas.h" | 
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 menu_listeners_.RemoveObserver(listener); | 128 menu_listeners_.RemoveObserver(listener); | 
| 128 } | 129 } | 
| 129 | 130 | 
| 130 gfx::Size AppMenuButton::GetPreferredSize() const { | 131 gfx::Size AppMenuButton::GetPreferredSize() const { | 
| 131 gfx::Rect rect(gfx::Size(kIconSize, kIconSize)); | 132 gfx::Rect rect(gfx::Size(kIconSize, kIconSize)); | 
| 132 rect.Inset(gfx::Insets(-ToolbarButton::kInteriorPadding)); | 133 rect.Inset(gfx::Insets(-ToolbarButton::kInteriorPadding)); | 
| 133 return rect.size(); | 134 return rect.size(); | 
| 134 } | 135 } | 
| 135 | 136 | 
| 136 void AppMenuButton::Layout() { | 137 void AppMenuButton::Layout() { | 
| 137 if (animation_) { | 138 if (new_icon_) { | 
| 139 new_icon_->SetBoundsRect(GetContentsBounds()); | |
| 138 ink_drop_container()->SetBoundsRect(GetLocalBounds()); | 140 ink_drop_container()->SetBoundsRect(GetLocalBounds()); | 
| 139 image()->SetBoundsRect(GetLocalBounds()); | 141 image()->SetBoundsRect(GetLocalBounds()); | 
| 140 return; | 142 return; | 
| 141 } | 143 } | 
| 142 | 144 | 
| 143 views::MenuButton::Layout(); | 145 views::MenuButton::Layout(); | 
| 144 } | 146 } | 
| 145 | 147 | 
| 146 void AppMenuButton::OnPaint(gfx::Canvas* canvas) { | 148 void AppMenuButton::OnThemeChanged() { | 
| 147 if (!animation_) { | 149 UpdateIcon(false); | 
| 148 views::MenuButton::OnPaint(canvas); | |
| 149 return; | |
| 150 } | |
| 151 | |
| 152 gfx::Rect bounds = GetLocalBounds(); | |
| 153 bounds.Inset(gfx::Insets(ToolbarButton::kInteriorPadding)); | |
| 154 animation_->PaintAppMenu(canvas, bounds); | |
| 155 } | 150 } | 
| 156 | 151 | 
| 157 void AppMenuButton::TabInsertedAt(TabStripModel* tab_strip_model, | 152 void AppMenuButton::TabInsertedAt(TabStripModel* tab_strip_model, | 
| 158 content::WebContents* contents, | 153 content::WebContents* contents, | 
| 159 int index, | 154 int index, | 
| 160 bool foreground) { | 155 bool foreground) { | 
| 161 AnimateIconIfPossible(); | 156 AnimateIconIfPossible(); | 
| 162 } | 157 } | 
| 163 | 158 | 
| 164 void AppMenuButton::AppMenuAnimationStarted() { | |
| 165 SetPaintToLayer(); | |
| 166 layer()->SetFillsBoundsOpaquely(false); | |
| 167 } | |
| 168 | |
| 169 void AppMenuButton::AppMenuAnimationEnded() { | |
| 170 DestroyLayer(); | |
| 171 } | |
| 172 | |
| 173 void AppMenuButton::InvalidateIcon() { | |
| 174 SchedulePaint(); | |
| 175 } | |
| 176 | |
| 177 void AppMenuButton::UpdateIcon(bool should_animate) { | 159 void AppMenuButton::UpdateIcon(bool should_animate) { | 
| 178 SkColor severity_color = gfx::kPlaceholderColor; | 160 SkColor severity_color = gfx::kPlaceholderColor; | 
| 179 SkColor toolbar_icon_color = | 161 SkColor toolbar_icon_color = | 
| 180 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); | 162 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); | 
| 181 const ui::NativeTheme* native_theme = GetNativeTheme(); | 163 const ui::NativeTheme* native_theme = GetNativeTheme(); | 
| 182 switch (severity_) { | 164 switch (severity_) { | 
| 183 case AppMenuIconController::Severity::NONE: | 165 case AppMenuIconController::Severity::NONE: | 
| 184 severity_color = toolbar_icon_color; | 166 severity_color = toolbar_icon_color; | 
| 185 break; | 167 break; | 
| 186 case AppMenuIconController::Severity::LOW: | 168 case AppMenuIconController::Severity::LOW: | 
| 187 severity_color = native_theme->GetSystemColor( | 169 severity_color = native_theme->GetSystemColor( | 
| 188 ui::NativeTheme::kColorId_AlertSeverityLow); | 170 ui::NativeTheme::kColorId_AlertSeverityLow); | 
| 189 break; | 171 break; | 
| 190 case AppMenuIconController::Severity::MEDIUM: | 172 case AppMenuIconController::Severity::MEDIUM: | 
| 191 severity_color = native_theme->GetSystemColor( | 173 severity_color = native_theme->GetSystemColor( | 
| 192 ui::NativeTheme::kColorId_AlertSeverityMedium); | 174 ui::NativeTheme::kColorId_AlertSeverityMedium); | 
| 193 break; | 175 break; | 
| 194 case AppMenuIconController::Severity::HIGH: | 176 case AppMenuIconController::Severity::HIGH: | 
| 195 severity_color = native_theme->GetSystemColor( | 177 severity_color = native_theme->GetSystemColor( | 
| 196 ui::NativeTheme::kColorId_AlertSeverityHigh); | 178 ui::NativeTheme::kColorId_AlertSeverityHigh); | 
| 197 break; | 179 break; | 
| 198 } | 180 } | 
| 199 | 181 | 
| 200 if (should_use_new_icon_) { | 182 if (should_use_new_icon_) { | 
| 201 if (!animation_) | 183 if (!new_icon_) { | 
| 202 animation_ = base::MakeUnique<AppMenuAnimation>(this, toolbar_icon_color); | 184 new_icon_ = new views::AnimatedIconView(kBrowserToolsAnimatedIcon); | 
| 185 new_icon_->set_can_process_events_within_subtree(false); | |
| 186 AddChildView(new_icon_); | |
| 187 } | |
| 203 | 188 | 
| 204 animation_->set_target_color(severity_color); | 189 // Only show a special color for severity when using the classic Chrome | 
| 190 // theme. Otherwise, we can't be sure that it contrasts with the toolbar | |
| 191 // background. | |
| 
 
Peter Kasting
2017/05/31 02:08:28
What about just always running the severity_color
 
Evan Stade
2017/05/31 17:08:16
I can experiment with that as a follow up, but eve
 
Peter Kasting
2017/05/31 17:24:31
If you put in red, you always get red out.  That's
 
 | |
| 192 new_icon_->set_color( | |
| 193 ThemeServiceFactory::GetForProfile(toolbar_view_->browser()->profile()) | |
| 194 ->UsingDefaultTheme() | |
| 195 ? severity_color | |
| 196 : toolbar_icon_color); | |
| 197 | |
| 205 if (should_animate) | 198 if (should_animate) | 
| 206 AnimateIconIfPossible(); | 199 AnimateIconIfPossible(); | 
| 207 | 200 | 
| 208 return; | 201 return; | 
| 209 } | 202 } | 
| 210 | 203 | 
| 211 const gfx::VectorIcon* icon_id = nullptr; | 204 const gfx::VectorIcon* icon_id = nullptr; | 
| 212 switch (type_) { | 205 switch (type_) { | 
| 213 case AppMenuIconController::IconType::NONE: | 206 case AppMenuIconController::IconType::NONE: | 
| 214 icon_id = &kBrowserToolsIcon; | 207 icon_id = &kBrowserToolsIcon; | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 227 gfx::CreateVectorIcon(*icon_id, severity_color)); | 220 gfx::CreateVectorIcon(*icon_id, severity_color)); | 
| 228 } | 221 } | 
| 229 | 222 | 
| 230 void AppMenuButton::SetTrailingMargin(int margin) { | 223 void AppMenuButton::SetTrailingMargin(int margin) { | 
| 231 margin_trailing_ = margin; | 224 margin_trailing_ = margin; | 
| 232 UpdateThemedBorder(); | 225 UpdateThemedBorder(); | 
| 233 InvalidateLayout(); | 226 InvalidateLayout(); | 
| 234 } | 227 } | 
| 235 | 228 | 
| 236 void AppMenuButton::AnimateIconIfPossible() { | 229 void AppMenuButton::AnimateIconIfPossible() { | 
| 237 if (!animation_ || !should_use_new_icon_ || | 230 if (!new_icon_ || !should_use_new_icon_ || | 
| 238 severity_ == AppMenuIconController::Severity::NONE) { | 231 severity_ == AppMenuIconController::Severity::NONE) { | 
| 239 return; | 232 return; | 
| 240 } | 233 } | 
| 241 | 234 | 
| 242 animation_->StartAnimation(); | 235 new_icon_->Animate(views::AnimatedIconView::END); | 
| 
 
sadrul
2017/05/30 17:06:51
Who calls Animate(START)?
 
Peter Kasting
2017/05/31 02:08:28
I assume no one, since this means "animate to the
 
 | |
| 243 } | 236 } | 
| 244 | 237 | 
| 245 const char* AppMenuButton::GetClassName() const { | 238 const char* AppMenuButton::GetClassName() const { | 
| 246 return "AppMenuButton"; | 239 return "AppMenuButton"; | 
| 247 } | 240 } | 
| 248 | 241 | 
| 249 std::unique_ptr<views::LabelButtonBorder> AppMenuButton::CreateDefaultBorder() | 242 std::unique_ptr<views::LabelButtonBorder> AppMenuButton::CreateDefaultBorder() | 
| 250 const { | 243 const { | 
| 251 std::unique_ptr<views::LabelButtonBorder> border = | 244 std::unique_ptr<views::LabelButtonBorder> border = | 
| 252 MenuButton::CreateDefaultBorder(); | 245 MenuButton::CreateDefaultBorder(); | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 return ui::DragDropTypes::DRAG_MOVE; | 292 return ui::DragDropTypes::DRAG_MOVE; | 
| 300 } | 293 } | 
| 301 | 294 | 
| 302 void AppMenuButton::OnDragExited() { | 295 void AppMenuButton::OnDragExited() { | 
| 303 weak_factory_.InvalidateWeakPtrs(); | 296 weak_factory_.InvalidateWeakPtrs(); | 
| 304 } | 297 } | 
| 305 | 298 | 
| 306 int AppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) { | 299 int AppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) { | 
| 307 return ui::DragDropTypes::DRAG_MOVE; | 300 return ui::DragDropTypes::DRAG_MOVE; | 
| 308 } | 301 } | 
| OLD | NEW |