| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 view_controller(); | 301 view_controller(); |
| 317 } | 302 } |
| 318 | 303 |
| 319 views::View* BrowserActionView::GetReferenceViewForPopup() { | 304 views::View* BrowserActionView::GetReferenceViewForPopup() { |
| 320 // Browser actions in the overflow menu can still show popups, so we may need | 305 // Browser actions in the overflow menu can still show popups, so we may need |
| 321 // a reference view other than this button's parent. If so, use the overflow | 306 // a reference view other than this button's parent. If so, use the overflow |
| 322 // view. | 307 // view. |
| 323 return visible() ? this : delegate_->GetOverflowReferenceView(); | 308 return visible() ? this : delegate_->GetOverflowReferenceView(); |
| 324 } | 309 } |
| 325 | 310 |
| 311 views::MenuButton* BrowserActionView::GetContextMenuButton() { |
| 312 DCHECK(visible()); // We should never show a context menu for a hidden item. |
| 313 return this; |
| 314 } |
| 315 |
| 326 content::WebContents* BrowserActionView::GetCurrentWebContents() { | 316 content::WebContents* BrowserActionView::GetCurrentWebContents() { |
| 327 return delegate_->GetCurrentWebContents(); | 317 return delegate_->GetCurrentWebContents(); |
| 328 } | 318 } |
| 329 | 319 |
| 330 void BrowserActionView::HideActivePopup() { | 320 void BrowserActionView::HideActivePopup() { |
| 331 delegate_->HideActivePopup(); | 321 delegate_->HideActivePopup(); |
| 332 } | 322 } |
| 333 | 323 |
| 334 void BrowserActionView::OnPopupShown(bool grant_tab_permissions) { | 324 void BrowserActionView::OnPopupShown(bool grant_tab_permissions) { |
| 335 delegate_->SetPopupOwner(this); | 325 delegate_->SetPopupOwner(this); |
| 336 if (grant_tab_permissions) | 326 // If this was through direct user action, we press the menu button. |
| 337 SetButtonPushed(); | 327 if (grant_tab_permissions) { |
| 328 // We set the state of the menu button we're using as a reference view, |
| 329 // which is either this or the overflow reference view. |
| 330 // This cast is safe because GetReferenceViewForPopup returns either |this| |
| 331 // or delegate_->GetOverflowReferenceView(), which returns a MenuButton. |
| 332 views::MenuButton* reference_view = |
| 333 static_cast<views::MenuButton*>(GetReferenceViewForPopup()); |
| 334 pressed_lock_.reset(new views::MenuButton::PressedLock(reference_view)); |
| 335 } |
| 338 } | 336 } |
| 339 | 337 |
| 340 void BrowserActionView::CleanupPopup() { | 338 void BrowserActionView::CleanupPopup() { |
| 341 // We need to do these actions synchronously (instead of closing and then | 339 // We need to do these actions synchronously (instead of closing and then |
| 342 // performing the rest of the cleanup in OnWidgetDestroyed()) because | 340 // performing the rest of the cleanup in OnWidgetDestroyed()) because |
| 343 // OnWidgetDestroyed() can be called asynchronously from Close(), and we need | 341 // OnWidgetDestroyed() can be called asynchronously from Close(), and we need |
| 344 // to keep the delegate's popup owner up-to-date. | 342 // to keep the delegate's popup owner up-to-date. |
| 345 SetButtonNotPushed(); | |
| 346 delegate_->SetPopupOwner(NULL); | 343 delegate_->SetPopupOwner(NULL); |
| 344 pressed_lock_.reset(); // Unpress the menu button if it was pressed. |
| 347 } | 345 } |
| 348 | |
| 349 void BrowserActionView::OnWillShowContextMenus() { | |
| 350 SetButtonPushed(); | |
| 351 } | |
| 352 | |
| 353 void BrowserActionView::OnContextMenuDone() { | |
| 354 SetButtonNotPushed(); | |
| 355 } | |
| OLD | NEW |