OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/browser_actions_container.h" |
6 | 6 |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_browser_event_router.h" | 10 #include "chrome/browser/extensions/extension_browser_event_router.h" |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 model_(NULL), | 354 model_(NULL), |
355 container_width_(0), | 355 container_width_(0), |
356 chevron_(NULL), | 356 chevron_(NULL), |
357 overflow_menu_(NULL), | 357 overflow_menu_(NULL), |
358 suppress_chevron_(false), | 358 suppress_chevron_(false), |
359 resize_amount_(0), | 359 resize_amount_(0), |
360 animation_target_size_(0), | 360 animation_target_size_(0), |
361 drop_indicator_position_(-1), | 361 drop_indicator_position_(-1), |
362 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), | 362 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), |
363 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) { | 363 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) { |
364 SetID(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 364 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
365 | 365 |
366 if (profile_->GetExtensionService()) { | 366 if (profile_->GetExtensionService()) { |
367 model_ = profile_->GetExtensionService()->toolbar_model(); | 367 model_ = profile_->GetExtensionService()->toolbar_model(); |
368 model_->AddObserver(this); | 368 model_->AddObserver(this); |
369 } | 369 } |
370 | 370 |
371 resize_animation_.reset(new ui::SlideAnimation(this)); | 371 resize_animation_.reset(new ui::SlideAnimation(this)); |
372 resize_area_ = new views::ResizeArea(this); | 372 resize_area_ = new views::ResizeArea(this); |
373 AddChildView(resize_area_); | 373 AddChildView(resize_area_); |
374 | 374 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 462 |
463 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | 463 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { |
464 SetVisible(!browser_action_views_.empty()); | 464 SetVisible(!browser_action_views_.empty()); |
465 owner_view_->Layout(); | 465 owner_view_->Layout(); |
466 owner_view_->SchedulePaint(); | 466 owner_view_->SchedulePaint(); |
467 } | 467 } |
468 | 468 |
469 size_t BrowserActionsContainer::VisibleBrowserActions() const { | 469 size_t BrowserActionsContainer::VisibleBrowserActions() const { |
470 size_t visible_actions = 0; | 470 size_t visible_actions = 0; |
471 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 471 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
472 if (browser_action_views_[i]->IsVisible()) | 472 if (browser_action_views_[i]->visible()) |
473 ++visible_actions; | 473 ++visible_actions; |
474 } | 474 } |
475 return visible_actions; | 475 return visible_actions; |
476 } | 476 } |
477 | 477 |
478 void BrowserActionsContainer::OnBrowserActionExecuted( | 478 void BrowserActionsContainer::OnBrowserActionExecuted( |
479 BrowserActionButton* button, | 479 BrowserActionButton* button, |
480 bool inspect_with_devtools) { | 480 bool inspect_with_devtools) { |
481 ExtensionAction* browser_action = button->browser_action(); | 481 ExtensionAction* browser_action = button->browser_action(); |
482 | 482 |
(...skipping 12 matching lines...) Expand all Loading... |
495 // Always hide the current popup, even if it's not the same. | 495 // Always hide the current popup, even if it's not the same. |
496 // Only one popup should be visible at a time. | 496 // Only one popup should be visible at a time. |
497 HidePopup(); | 497 HidePopup(); |
498 | 498 |
499 if (same_showing) | 499 if (same_showing) |
500 return; | 500 return; |
501 | 501 |
502 // We can get the execute event for browser actions that are not visible, | 502 // We can get the execute event for browser actions that are not visible, |
503 // since buttons can be activated from the overflow menu (chevron). In that | 503 // since buttons can be activated from the overflow menu (chevron). In that |
504 // case we show the popup as originating from the chevron. | 504 // case we show the popup as originating from the chevron. |
505 View* reference_view = button->parent()->IsVisible() ? button : chevron_; | 505 View* reference_view = button->parent()->visible() ? button : chevron_; |
506 gfx::Point origin; | 506 gfx::Point origin; |
507 View::ConvertPointToScreen(reference_view, &origin); | 507 View::ConvertPointToScreen(reference_view, &origin); |
508 gfx::Rect rect = reference_view->bounds(); | 508 gfx::Rect rect = reference_view->bounds(); |
509 rect.set_origin(origin); | 509 rect.set_origin(origin); |
510 | 510 |
511 BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? | 511 BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? |
512 BubbleBorder::TOP_LEFT : BubbleBorder::TOP_RIGHT; | 512 BubbleBorder::TOP_LEFT : BubbleBorder::TOP_RIGHT; |
513 | 513 |
514 popup_ = ExtensionPopup::Show(button->GetPopupUrl(), browser_, rect, | 514 popup_ = ExtensionPopup::Show(button->GetPopupUrl(), browser_, rect, |
515 arrow_location, inspect_with_devtools, | 515 arrow_location, inspect_with_devtools, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 return ui::DragDropTypes::DRAG_NONE; | 665 return ui::DragDropTypes::DRAG_NONE; |
666 | 666 |
667 // Make sure we have the same view as we started with. | 667 // Make sure we have the same view as we started with. |
668 DCHECK_EQ(browser_action_views_[data.index()]->button()->extension()->id(), | 668 DCHECK_EQ(browser_action_views_[data.index()]->button()->extension()->id(), |
669 data.id()); | 669 data.id()); |
670 DCHECK(model_); | 670 DCHECK(model_); |
671 | 671 |
672 size_t i = 0; | 672 size_t i = 0; |
673 for (; i < browser_action_views_.size(); ++i) { | 673 for (; i < browser_action_views_.size(); ++i) { |
674 int view_x = browser_action_views_[i]->GetMirroredBounds().x(); | 674 int view_x = browser_action_views_[i]->GetMirroredBounds().x(); |
675 if (!browser_action_views_[i]->IsVisible() || | 675 if (!browser_action_views_[i]->visible() || |
676 (base::i18n::IsRTL() ? (view_x < drop_indicator_position_) : | 676 (base::i18n::IsRTL() ? (view_x < drop_indicator_position_) : |
677 (view_x >= drop_indicator_position_))) { | 677 (view_x >= drop_indicator_position_))) { |
678 // We have reached the end of the visible icons or found one that has a | 678 // We have reached the end of the visible icons or found one that has a |
679 // higher x position than the drop point. | 679 // higher x position than the drop point. |
680 break; | 680 break; |
681 } | 681 } |
682 } | 682 } |
683 | 683 |
684 // |i| now points to the item to the right of the drop indicator*, which is | 684 // |i| now points to the item to the right of the drop indicator*, which is |
685 // correct when dragging an icon to the left. When dragging to the right, | 685 // correct when dragging an icon to the left. When dragging to the right, |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 } | 815 } |
816 | 816 |
817 void BrowserActionsContainer::TestExecuteBrowserAction(int index) { | 817 void BrowserActionsContainer::TestExecuteBrowserAction(int index) { |
818 BrowserActionButton* button = browser_action_views_[index]->button(); | 818 BrowserActionButton* button = browser_action_views_[index]->button(); |
819 OnBrowserActionExecuted(button, false); | 819 OnBrowserActionExecuted(button, false); |
820 } | 820 } |
821 | 821 |
822 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { | 822 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { |
823 model_->SetVisibleIconCount(icons); | 823 model_->SetVisibleIconCount(icons); |
824 chevron_->SetVisible(icons < browser_action_views_.size()); | 824 chevron_->SetVisible(icons < browser_action_views_.size()); |
825 container_width_ = IconCountToWidth(icons, chevron_->IsVisible()); | 825 container_width_ = IconCountToWidth(icons, chevron_->visible()); |
826 Layout(); | 826 Layout(); |
827 SchedulePaint(); | 827 SchedulePaint(); |
828 } | 828 } |
829 | 829 |
830 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { | 830 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
831 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while | 831 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while |
832 // dragging (like we do for tab dragging). | 832 // dragging (like we do for tab dragging). |
833 if (drop_indicator_position_ > -1) { | 833 if (drop_indicator_position_ > -1) { |
834 // The two-pixel width drop indicator. | 834 // The two-pixel width drop indicator. |
835 static const int kDropIndicatorWidth = 2; | 835 static const int kDropIndicatorWidth = 2; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 chevron_->SetIcon(*tp->GetBitmapNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 990 chevron_->SetIcon(*tp->GetBitmapNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
991 chevron_->SetHoverIcon(*tp->GetBitmapNamed(IDR_BROWSER_ACTIONS_OVERFLOW_H)); | 991 chevron_->SetHoverIcon(*tp->GetBitmapNamed(IDR_BROWSER_ACTIONS_OVERFLOW_H)); |
992 chevron_->SetPushedIcon(*tp->GetBitmapNamed(IDR_BROWSER_ACTIONS_OVERFLOW_P)); | 992 chevron_->SetPushedIcon(*tp->GetBitmapNamed(IDR_BROWSER_ACTIONS_OVERFLOW_P)); |
993 } | 993 } |
994 | 994 |
995 void BrowserActionsContainer::SetContainerWidth() { | 995 void BrowserActionsContainer::SetContainerWidth() { |
996 int visible_actions = model_->GetVisibleIconCount(); | 996 int visible_actions = model_->GetVisibleIconCount(); |
997 if (visible_actions < 0) // All icons should be visible. | 997 if (visible_actions < 0) // All icons should be visible. |
998 visible_actions = model_->size(); | 998 visible_actions = model_->size(); |
999 chevron_->SetVisible(static_cast<size_t>(visible_actions) < model_->size()); | 999 chevron_->SetVisible(static_cast<size_t>(visible_actions) < model_->size()); |
1000 container_width_ = IconCountToWidth(visible_actions, chevron_->IsVisible()); | 1000 container_width_ = IconCountToWidth(visible_actions, chevron_->visible()); |
1001 } | 1001 } |
1002 | 1002 |
1003 void BrowserActionsContainer::CloseOverflowMenu() { | 1003 void BrowserActionsContainer::CloseOverflowMenu() { |
1004 if (overflow_menu_) | 1004 if (overflow_menu_) |
1005 overflow_menu_->CancelMenu(); | 1005 overflow_menu_->CancelMenu(); |
1006 } | 1006 } |
1007 | 1007 |
1008 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { | 1008 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { |
1009 show_menu_task_factory_.RevokeAll(); | 1009 show_menu_task_factory_.RevokeAll(); |
1010 } | 1010 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 } | 1095 } |
1096 } | 1096 } |
1097 | 1097 |
1098 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1098 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
1099 const Extension* extension) { | 1099 const Extension* extension) { |
1100 // Only display incognito-enabled extensions while in incognito mode. | 1100 // Only display incognito-enabled extensions while in incognito mode. |
1101 return | 1101 return |
1102 (!profile_->IsOffTheRecord() || | 1102 (!profile_->IsOffTheRecord() || |
1103 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); | 1103 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); |
1104 } | 1104 } |
OLD | NEW |