| 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 AddChildView(new_icon_); |
| 186 } |
| 203 | 187 |
| 204 animation_->set_target_color(severity_color); | 188 // Only show a special color for severity when using the classic Chrome |
| 189 // theme. Otherwise, we can't be sure that it contrasts with the toolbar |
| 190 // background. |
| 191 new_icon_->set_color( |
| 192 ThemeServiceFactory::GetForProfile(toolbar_view_->browser()->profile()) |
| 193 ->UsingDefaultTheme() |
| 194 ? severity_color |
| 195 : toolbar_icon_color); |
| 196 |
| 205 if (should_animate) | 197 if (should_animate) |
| 206 AnimateIconIfPossible(); | 198 AnimateIconIfPossible(); |
| 207 | 199 |
| 208 return; | 200 return; |
| 209 } | 201 } |
| 210 | 202 |
| 211 const gfx::VectorIcon* icon_id = nullptr; | 203 const gfx::VectorIcon* icon_id = nullptr; |
| 212 switch (type_) { | 204 switch (type_) { |
| 213 case AppMenuIconController::IconType::NONE: | 205 case AppMenuIconController::IconType::NONE: |
| 214 icon_id = &kBrowserToolsIcon; | 206 icon_id = &kBrowserToolsIcon; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 227 gfx::CreateVectorIcon(*icon_id, severity_color)); | 219 gfx::CreateVectorIcon(*icon_id, severity_color)); |
| 228 } | 220 } |
| 229 | 221 |
| 230 void AppMenuButton::SetTrailingMargin(int margin) { | 222 void AppMenuButton::SetTrailingMargin(int margin) { |
| 231 margin_trailing_ = margin; | 223 margin_trailing_ = margin; |
| 232 UpdateThemedBorder(); | 224 UpdateThemedBorder(); |
| 233 InvalidateLayout(); | 225 InvalidateLayout(); |
| 234 } | 226 } |
| 235 | 227 |
| 236 void AppMenuButton::AnimateIconIfPossible() { | 228 void AppMenuButton::AnimateIconIfPossible() { |
| 237 if (!animation_ || !should_use_new_icon_ || | 229 if (!new_icon_ || !should_use_new_icon_ || |
| 238 severity_ == AppMenuIconController::Severity::NONE) { | 230 severity_ == AppMenuIconController::Severity::NONE) { |
| 239 return; | 231 return; |
| 240 } | 232 } |
| 241 | 233 |
| 242 animation_->StartAnimation(); | 234 new_icon_->Animate(views::AnimatedIconView::END); |
| 243 } | 235 } |
| 244 | 236 |
| 245 const char* AppMenuButton::GetClassName() const { | 237 const char* AppMenuButton::GetClassName() const { |
| 246 return "AppMenuButton"; | 238 return "AppMenuButton"; |
| 247 } | 239 } |
| 248 | 240 |
| 249 std::unique_ptr<views::LabelButtonBorder> AppMenuButton::CreateDefaultBorder() | 241 std::unique_ptr<views::LabelButtonBorder> AppMenuButton::CreateDefaultBorder() |
| 250 const { | 242 const { |
| 251 std::unique_ptr<views::LabelButtonBorder> border = | 243 std::unique_ptr<views::LabelButtonBorder> border = |
| 252 MenuButton::CreateDefaultBorder(); | 244 MenuButton::CreateDefaultBorder(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 return ui::DragDropTypes::DRAG_MOVE; | 291 return ui::DragDropTypes::DRAG_MOVE; |
| 300 } | 292 } |
| 301 | 293 |
| 302 void AppMenuButton::OnDragExited() { | 294 void AppMenuButton::OnDragExited() { |
| 303 weak_factory_.InvalidateWeakPtrs(); | 295 weak_factory_.InvalidateWeakPtrs(); |
| 304 } | 296 } |
| 305 | 297 |
| 306 int AppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) { | 298 int AppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) { |
| 307 return ui::DragDropTypes::DRAG_MOVE; | 299 return ui::DragDropTypes::DRAG_MOVE; |
| 308 } | 300 } |
| OLD | NEW |