Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: chrome/browser/views/toolbar_view.cc

Issue 53096: Broadcast a state change notification from the toolbar to the RenderWidgetHos... (Closed) Base URL: svn://chrome-svn/chrome/branches/release_154.next/src/
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/views/toolbar_view.h ('k') | chrome/common/notification_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/toolbar_view.h" 5 #include "chrome/browser/views/toolbar_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // Padding to the right of the location bar 59 // Padding to the right of the location bar
60 static const int kPaddingRight = 2; 60 static const int kPaddingRight = 2;
61 61
62 BrowserToolbarView::BrowserToolbarView(CommandController* controller, 62 BrowserToolbarView::BrowserToolbarView(CommandController* controller,
63 Browser* browser) 63 Browser* browser)
64 : EncodingMenuControllerDelegate(browser, controller), 64 : EncodingMenuControllerDelegate(browser, controller),
65 controller_(controller), 65 controller_(controller),
66 model_(browser->toolbar_model()), 66 model_(browser->toolbar_model()),
67 back_(NULL), 67 back_(NULL),
68 forward_(NULL), 68 forward_(NULL),
69 threedee_(NULL),
69 reload_(NULL), 70 reload_(NULL),
70 home_(NULL), 71 home_(NULL),
71 star_(NULL), 72 star_(NULL),
72 location_bar_(NULL), 73 location_bar_(NULL),
73 go_(NULL), 74 go_(NULL),
74 profile_(NULL), 75 profile_(NULL),
75 acc_focused_view_(NULL), 76 acc_focused_view_(NULL),
76 browser_(browser), 77 browser_(browser),
77 tab_(NULL) { 78 tab_(NULL) {
78 back_menu_model_.reset(new BackForwardMenuModel( 79 back_menu_model_.reset(new BackForwardMenuModel(
79 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE)); 80 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE));
80 forward_menu_model_.reset(new BackForwardMenuModel( 81 forward_menu_model_.reset(new BackForwardMenuModel(
81 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE)); 82 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE));
82 83
83 if (browser->GetType() == BrowserType::TABBED_BROWSER) 84 if (browser->GetType() == BrowserType::TABBED_BROWSER)
84 display_mode_ = DISPLAYMODE_NORMAL; 85 display_mode_ = DISPLAYMODE_NORMAL;
85 else 86 else
86 display_mode_ = DISPLAYMODE_LOCATION; 87 display_mode_ = DISPLAYMODE_LOCATION;
88
89 NotificationService::current()->AddObserver(
90 this,
91 NOTIFY_THREEDEE_TOGGLED,
92 NotificationService::AllSources());
87 } 93 }
88 94
89 BrowserToolbarView::~BrowserToolbarView() { 95 BrowserToolbarView::~BrowserToolbarView() {
96 NotificationService::current()->RemoveObserver(
97 this,
98 NOTIFY_THREEDEE_TOGGLED,
99 NotificationService::AllSources());
90 } 100 }
91 101
92 void BrowserToolbarView::Init(Profile* profile) { 102 void BrowserToolbarView::Init(Profile* profile) {
93 // Create all the individual Views in the Toolbar. 103 // Create all the individual Views in the Toolbar.
94 CreateLeftSideControls(); 104 CreateLeftSideControls();
95 CreateCenterStack(profile); 105 CreateCenterStack(profile);
96 CreateRightSideControls(profile); 106 CreateRightSideControls(profile);
97 107
98 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); 108 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this);
99 109
(...skipping 28 matching lines...) Expand all
128 forward_->SetImage(views::Button::BS_PUSHED, 138 forward_->SetImage(views::Button::BS_PUSHED,
129 rb.GetBitmapNamed(IDR_FORWARD_P)); 139 rb.GetBitmapNamed(IDR_FORWARD_P));
130 forward_->SetImage(views::Button::BS_DISABLED, 140 forward_->SetImage(views::Button::BS_DISABLED,
131 rb.GetBitmapNamed(IDR_FORWARD_D)); 141 rb.GetBitmapNamed(IDR_FORWARD_D));
132 forward_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_FORWARD)); 142 forward_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_FORWARD));
133 forward_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_FORWARD)); 143 forward_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_FORWARD));
134 forward_->SetID(VIEW_ID_FORWARD_BUTTON); 144 forward_->SetID(VIEW_ID_FORWARD_BUTTON);
135 AddChildView(forward_); 145 AddChildView(forward_);
136 controller_->AddManagedButton(forward_, IDC_FORWARD); 146 controller_->AddManagedButton(forward_, IDC_FORWARD);
137 147
148 threedee_ = new views::ToggleButton();
149 threedee_->SetListener(this, IDC_THREEDEE);
150 threedee_->SetImage(views::BaseButton::BS_NORMAL,
151 rb.GetBitmapNamed(IDR_3D));
152 threedee_->SetImage(views::BaseButton::BS_HOT,
153 rb.GetBitmapNamed(IDR_3D_H));
154 threedee_->SetImage(views::BaseButton::BS_PUSHED,
155 rb.GetBitmapNamed(IDR_3D_P));
156 threedee_->SetToggledImage(views::BaseButton::BS_NORMAL,
157 rb.GetBitmapNamed(IDR_3D_C));
158 threedee_->SetID(VIEW_ID_3D_BUTTON);
159 AddChildView(threedee_);
160
138 reload_ = new views::Button(); 161 reload_ = new views::Button();
139 reload_->SetImage(views::Button::BS_NORMAL, rb.GetBitmapNamed(IDR_RELOAD)); 162 reload_->SetImage(views::Button::BS_NORMAL, rb.GetBitmapNamed(IDR_RELOAD));
140 reload_->SetImage(views::Button::BS_HOT, rb.GetBitmapNamed(IDR_RELOAD_H)); 163 reload_->SetImage(views::Button::BS_HOT, rb.GetBitmapNamed(IDR_RELOAD_H));
141 reload_->SetImage(views::Button::BS_PUSHED, rb.GetBitmapNamed(IDR_RELOAD_P)); 164 reload_->SetImage(views::Button::BS_PUSHED, rb.GetBitmapNamed(IDR_RELOAD_P));
142 reload_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_RELOAD)); 165 reload_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_RELOAD));
143 reload_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_RELOAD)); 166 reload_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_RELOAD));
144 reload_->SetID(VIEW_ID_RELOAD_BUTTON); 167 reload_->SetID(VIEW_ID_RELOAD_BUTTON);
145 AddChildView(reload_); 168 AddChildView(reload_);
146 controller_->AddManagedButton(reload_, IDC_RELOAD); 169 controller_->AddManagedButton(reload_, IDC_RELOAD);
147 170
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 int right_side_width = 0; 280 int right_side_width = 0;
258 if (IsDisplayModeNormal()) { 281 if (IsDisplayModeNormal()) {
259 sz = back_->GetPreferredSize(); 282 sz = back_->GetPreferredSize();
260 back_->SetBounds(kControlIndent, kControlVertOffset, sz.width(), 283 back_->SetBounds(kControlIndent, kControlVertOffset, sz.width(),
261 sz.height()); 284 sz.height());
262 285
263 sz = forward_->GetPreferredSize(); 286 sz = forward_->GetPreferredSize();
264 forward_->SetBounds(back_->x() + back_->width(), kControlVertOffset, 287 forward_->SetBounds(back_->x() + back_->width(), kControlVertOffset,
265 sz.width(), sz.height()); 288 sz.width(), sz.height());
266 289
267 sz = reload_->GetPreferredSize(); 290 if (threedee_) {
268 reload_->SetBounds(forward_->x() + forward_->width() + 291 sz = threedee_->GetPreferredSize();
269 kControlHorizOffset, 292 threedee_->SetBounds(forward_->x() + forward_->width() + kControlHorizOffs et,
270 kControlVertOffset, sz.width(), sz.height()); 293 kControlVertOffset, reload_->GetPreferredSize().width() ,
294 sz.height());
295
296 reload_->SetBounds(threedee_->x() + threedee_->width() + kControlHorizOffs et,
297 kControlVertOffset, reload_->GetPreferredSize().width() ,
298 sz.height());
299 } else {
300 sz = reload_->GetPreferredSize();
301 reload_->SetBounds(forward_->x() + forward_->width() +
302 kControlHorizOffset,
303 kControlVertOffset, sz.width(), sz.height());
304 }
271 305
272 int offset = 0; 306 int offset = 0;
273 if (show_home_button_.GetValue()) { 307 if (show_home_button_.GetValue()) {
274 sz = home_->GetPreferredSize(); 308 sz = home_->GetPreferredSize();
275 offset = kControlHorizOffset; 309 offset = kControlHorizOffset;
276 home_->SetVisible(true); 310 home_->SetVisible(true);
277 } else { 311 } else {
278 sz = gfx::Size(); 312 sz = gfx::Size();
279 home_->SetVisible(false); 313 home_->SetVisible(false);
280 } 314 }
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 724
691 void BrowserToolbarView::Observe(NotificationType type, 725 void BrowserToolbarView::Observe(NotificationType type,
692 const NotificationSource& source, 726 const NotificationSource& source,
693 const NotificationDetails& details) { 727 const NotificationDetails& details) {
694 if (type == NOTIFY_PREF_CHANGED) { 728 if (type == NOTIFY_PREF_CHANGED) {
695 std::wstring* pref_name = Details<std::wstring>(details).ptr(); 729 std::wstring* pref_name = Details<std::wstring>(details).ptr();
696 if (*pref_name == prefs::kShowHomeButton) { 730 if (*pref_name == prefs::kShowHomeButton) {
697 Layout(); 731 Layout();
698 SchedulePaint(); 732 SchedulePaint();
699 } 733 }
734 } else if (type == NOTIFY_THREEDEE_TOGGLED) {
735 // Redraw the window when the user changes this setting.
736 threedee_->SetToggled(g_threedee_enabled);
737 }
738 }
739
740 void BrowserToolbarView::ButtonPressed(views::BaseButton* sender) {
741 if (sender->GetTag() == IDC_THREEDEE) {
742 g_threedee_enabled = !g_threedee_enabled;
743 // The toggle state of the button will get changed in our observer (to keep
744 // all toolbars in sync).
745
746 NotificationService::current()->Notify(
747 NOTIFY_THREEDEE_TOGGLED,
748 NotificationService::AllSources(),
749 NotificationService::NoDetails());
750
751 return;
700 } 752 }
701 } 753 }
702 754
703 bool BrowserToolbarView::GetAcceleratorInfo(int id, 755 bool BrowserToolbarView::GetAcceleratorInfo(int id,
704 views::Accelerator* accel) { 756 views::Accelerator* accel) {
705 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators 757 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators
706 // anywhere so we need to check for them explicitly here. 758 // anywhere so we need to check for them explicitly here.
707 // TODO(cpu) Bug 1109102. Query WebKit land for the actual bindings. 759 // TODO(cpu) Bug 1109102. Query WebKit land for the actual bindings.
708 switch (id) { 760 switch (id) {
709 case IDC_CUT: 761 case IDC_CUT:
710 *accel = views::Accelerator(L'X', false, true, false); 762 *accel = views::Accelerator(L'X', false, true, false);
711 return true; 763 return true;
712 case IDC_COPY: 764 case IDC_COPY:
713 *accel = views::Accelerator(L'C', false, true, false); 765 *accel = views::Accelerator(L'C', false, true, false);
714 return true; 766 return true;
715 case IDC_PASTE: 767 case IDC_PASTE:
716 *accel = views::Accelerator(L'V', false, true, false); 768 *accel = views::Accelerator(L'V', false, true, false);
717 return true; 769 return true;
718 } 770 }
719 // Else, we retrieve the accelerator information from the frame. 771 // Else, we retrieve the accelerator information from the frame.
720 return GetContainer()->GetAccelerator(id, accel); 772 return GetContainer()->GetAccelerator(id, accel);
721 } 773 }
722 774
OLDNEW
« no previous file with comments | « chrome/browser/views/toolbar_view.h ('k') | chrome/common/notification_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698