| 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/browser_action_view.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 void BrowserActionView::ButtonPressed(views::Button* sender, | 123 void BrowserActionView::ButtonPressed(views::Button* sender, |
| 124 const ui::Event& event) { | 124 const ui::Event& event) { |
| 125 view_controller_->ExecuteActionByUser(); | 125 view_controller_->ExecuteActionByUser(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void BrowserActionView::UpdateState() { | 128 void BrowserActionView::UpdateState() { |
| 129 int tab_id = view_controller_->GetCurrentTabId(); | 129 int tab_id = view_controller_->GetCurrentTabId(); |
| 130 if (tab_id < 0) | 130 if (tab_id < 0) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 if (!IsEnabled(tab_id)) { | 133 if (!IsEnabled(tab_id)) |
| 134 SetState(views::CustomButton::STATE_DISABLED); | 134 SetState(views::CustomButton::STATE_DISABLED); |
| 135 } else { | |
| 136 SetState(menu_visible_ ? | |
| 137 views::CustomButton::STATE_PRESSED : | |
| 138 views::CustomButton::STATE_NORMAL); | |
| 139 } | |
| 140 | 135 |
| 141 gfx::ImageSkia icon = *view_controller_->GetIcon(tab_id).ToImageSkia(); | 136 gfx::ImageSkia icon = *view_controller_->GetIcon(tab_id).ToImageSkia(); |
| 142 | 137 |
| 143 if (!icon.isNull()) { | 138 if (!icon.isNull()) { |
| 144 if (!extension_action()->GetIsVisible(tab_id)) | 139 if (!extension_action()->GetIsVisible(tab_id)) |
| 145 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); | 140 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); |
| 146 | 141 |
| 147 ThemeService* theme = ThemeServiceFactory::GetForProfile( | 142 ThemeService* theme = ThemeServiceFactory::GetForProfile( |
| 148 view_controller_->browser()->profile()); | 143 view_controller_->browser()->profile()); |
| 149 | 144 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 LabelButton::OnGestureEvent(event); | 243 LabelButton::OnGestureEvent(event); |
| 249 } | 244 } |
| 250 | 245 |
| 251 scoped_ptr<LabelButtonBorder> BrowserActionView::CreateDefaultBorder() const { | 246 scoped_ptr<LabelButtonBorder> BrowserActionView::CreateDefaultBorder() const { |
| 252 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); | 247 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); |
| 253 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, | 248 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, |
| 254 kBorderInset, kBorderInset)); | 249 kBorderInset, kBorderInset)); |
| 255 return border.Pass(); | 250 return border.Pass(); |
| 256 } | 251 } |
| 257 | 252 |
| 258 void BrowserActionView::SetButtonPushed() { | |
| 259 SetState(views::CustomButton::STATE_PRESSED); | |
| 260 menu_visible_ = true; | |
| 261 } | |
| 262 | |
| 263 void BrowserActionView::SetButtonNotPushed() { | |
| 264 SetState(views::CustomButton::STATE_NORMAL); | |
| 265 menu_visible_ = false; | |
| 266 } | |
| 267 | |
| 268 bool BrowserActionView::IsEnabled(int tab_id) const { | 253 bool BrowserActionView::IsEnabled(int tab_id) const { |
| 269 return view_controller_->extension_action()->GetIsVisible(tab_id); | 254 return view_controller_->extension_action()->GetIsVisible(tab_id); |
| 270 } | 255 } |
| 271 | 256 |
| 272 gfx::ImageSkia BrowserActionView::GetIconWithBadge() { | 257 gfx::ImageSkia BrowserActionView::GetIconWithBadge() { |
| 273 int tab_id = view_controller_->GetCurrentTabId(); | 258 int tab_id = view_controller_->GetCurrentTabId(); |
| 274 gfx::Size spacing(0, ToolbarView::kVertSpacing); | 259 gfx::Size spacing(0, ToolbarView::kVertSpacing); |
| 275 gfx::ImageSkia icon = *view_controller_->GetIcon(tab_id).ToImageSkia(); | 260 gfx::ImageSkia icon = *view_controller_->GetIcon(tab_id).ToImageSkia(); |
| 276 if (!IsEnabled(tab_id)) | 261 if (!IsEnabled(tab_id)) |
| 277 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); | 262 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 return delegate_->GetCurrentWebContents(); | 312 return delegate_->GetCurrentWebContents(); |
| 328 } | 313 } |
| 329 | 314 |
| 330 void BrowserActionView::HideActivePopup() { | 315 void BrowserActionView::HideActivePopup() { |
| 331 delegate_->HideActivePopup(); | 316 delegate_->HideActivePopup(); |
| 332 } | 317 } |
| 333 | 318 |
| 334 void BrowserActionView::OnPopupShown(bool grant_tab_permissions) { | 319 void BrowserActionView::OnPopupShown(bool grant_tab_permissions) { |
| 335 delegate_->SetPopupOwner(this); | 320 delegate_->SetPopupOwner(this); |
| 336 if (grant_tab_permissions) | 321 if (grant_tab_permissions) |
| 337 SetButtonPushed(); | 322 SetMenuVisible(true); |
| 338 } | 323 } |
| 339 | 324 |
| 340 void BrowserActionView::CleanupPopup() { | 325 void BrowserActionView::CleanupPopup() { |
| 341 // We need to do these actions synchronously (instead of closing and then | 326 // We need to do these actions synchronously (instead of closing and then |
| 342 // performing the rest of the cleanup in OnWidgetDestroyed()) because | 327 // performing the rest of the cleanup in OnWidgetDestroyed()) because |
| 343 // OnWidgetDestroyed() can be called asynchronously from Close(), and we need | 328 // OnWidgetDestroyed() can be called asynchronously from Close(), and we need |
| 344 // to keep the delegate's popup owner up-to-date. | 329 // to keep the delegate's popup owner up-to-date. |
| 345 SetButtonNotPushed(); | 330 SetMenuVisible(false); |
| 346 delegate_->SetPopupOwner(NULL); | 331 delegate_->SetPopupOwner(NULL); |
| 347 } | 332 } |
| 348 | 333 |
| 349 void BrowserActionView::OnWillShowContextMenus() { | 334 void BrowserActionView::OnWillShowContextMenus() { |
| 350 SetButtonPushed(); | 335 SetMenuVisible(true); |
| 351 } | 336 } |
| 352 | 337 |
| 353 void BrowserActionView::OnContextMenuDone() { | 338 void BrowserActionView::OnContextMenuDone() { |
| 354 SetButtonNotPushed(); | 339 SetMenuVisible(false); |
| 355 } | 340 } |
| 341 |
| 342 void BrowserActionView::SetMenuVisible(bool menu_visible) { |
| 343 // We set the state of the menu button we're using as a reference view, which |
| 344 // is either this or the overflow reference view. |
| 345 // This cast is safe because GetReferenceViewForPopup returns either |this| |
| 346 // or delegate_->GetOverflowReferenceView(), which returns a MenuButton. |
| 347 views::MenuButton* reference_view = |
| 348 static_cast<views::MenuButton*>(GetReferenceViewForPopup()); |
| 349 if (menu_visible) |
| 350 reference_view->AttachMenu(); |
| 351 else |
| 352 reference_view->DetachMenu(); |
| 353 } |
| OLD | NEW |