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

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

Issue 486022: Implement context menu for page and browser actions (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/browser_actions_container.h" 5 #include "chrome/browser/views/browser_actions_container.h"
6 6
7 #include "app/gfx/canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 //////////////////////////////////////////////////////////////////////////////// 50 ////////////////////////////////////////////////////////////////////////////////
51 // BrowserActionButton 51 // BrowserActionButton
52 52
53 BrowserActionButton::BrowserActionButton(Extension* extension, 53 BrowserActionButton::BrowserActionButton(Extension* extension,
54 BrowserActionsContainer* panel) 54 BrowserActionsContainer* panel)
55 : MenuButton(this, L"", NULL, false), 55 : MenuButton(this, L"", NULL, false),
56 browser_action_(extension->browser_action()), 56 browser_action_(extension->browser_action()),
57 extension_(extension), 57 extension_(extension),
58 tracker_(NULL), 58 tracker_(NULL),
59 showing_context_menu_(false),
59 panel_(panel) { 60 panel_(panel) {
60 set_alignment(TextButton::ALIGN_CENTER); 61 set_alignment(TextButton::ALIGN_CENTER);
61 62
62 // No UpdateState() here because View heirarchy not setup yet. Our parent 63 // No UpdateState() here because View hierarchy not setup yet. Our parent
63 // should call UpdateState() after creation. 64 // should call UpdateState() after creation.
64 65
65 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, 66 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
66 Source<ExtensionAction>(browser_action_)); 67 Source<ExtensionAction>(browser_action_));
67 68
68 // The Browser Action API does not allow the default icon path to be changed 69 // The Browser Action API does not allow the default icon path to be changed
69 // at runtime, so we can load this now and cache it. 70 // at runtime, so we can load this now and cache it.
70 std::string relative_path = browser_action_->default_icon_path(); 71 std::string relative_path = browser_action_->default_icon_path();
71 if (relative_path.empty()) 72 if (relative_path.empty())
72 return; 73 return;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // The return value of this method is returned via OnMousePressed. 149 // The return value of this method is returned via OnMousePressed.
149 // We need to return false here since we're handing off focus to another 150 // We need to return false here since we're handing off focus to another
150 // widget/view, and true will grab it right back and try to send events 151 // widget/view, and true will grab it right back and try to send events
151 // to us. 152 // to us.
152 return false; 153 return false;
153 } 154 }
154 return true; 155 return true;
155 } 156 }
156 157
157 bool BrowserActionButton::OnMousePressed(const views::MouseEvent& e) { 158 bool BrowserActionButton::OnMousePressed(const views::MouseEvent& e) {
158 if (IsPopup()) 159 showing_context_menu_ = e.IsRightMouseButton();
160 if (showing_context_menu_) {
161 SetButtonPushed();
162
163 // Get the top left point of this button in screen coordinates.
164 gfx::Point point = gfx::Point(0, 0);
165 ConvertPointToScreen(this, &point);
166
167 // Make the menu appear below the button.
168 point.Offset(0, height());
169
170 if (!context_menu_.get())
171 context_menu_.reset(new ExtensionActionContextMenu());
172 context_menu_->Run(extension(), point);
173
174 SetButtonNotPushed();
175 return false;
176 } else if (IsPopup()) {
159 return MenuButton::OnMousePressed(e); 177 return MenuButton::OnMousePressed(e);
178 }
160 return TextButton::OnMousePressed(e); 179 return TextButton::OnMousePressed(e);
161 } 180 }
162 181
163 void BrowserActionButton::OnMouseReleased(const views::MouseEvent& e, 182 void BrowserActionButton::OnMouseReleased(const views::MouseEvent& e,
164 bool canceled) { 183 bool canceled) {
165 if (IsPopup()) { 184 if (IsPopup() || showing_context_menu_) {
166 // TODO(erikkay) this never actually gets called (probably because of the 185 // TODO(erikkay) this never actually gets called (probably because of the
167 // loss of focus). 186 // loss of focus).
168 MenuButton::OnMouseReleased(e, canceled); 187 MenuButton::OnMouseReleased(e, canceled);
169 } else { 188 } else {
170 TextButton::OnMouseReleased(e, canceled); 189 TextButton::OnMouseReleased(e, canceled);
171 } 190 }
172 } 191 }
173 192
174 bool BrowserActionButton::OnKeyReleased(const views::KeyEvent& e) { 193 bool BrowserActionButton::OnKeyReleased(const views::KeyEvent& e) {
175 if (IsPopup()) 194 if (IsPopup())
176 return MenuButton::OnKeyReleased(e); 195 return MenuButton::OnKeyReleased(e);
177 return TextButton::OnKeyReleased(e); 196 return TextButton::OnKeyReleased(e);
178 } 197 }
179 198
180 void BrowserActionButton::OnMouseExited(const views::MouseEvent& e) { 199 void BrowserActionButton::OnMouseExited(const views::MouseEvent& e) {
181 if (IsPopup()) 200 if (IsPopup() || showing_context_menu_)
182 MenuButton::OnMouseExited(e); 201 MenuButton::OnMouseExited(e);
183 else 202 else
184 TextButton::OnMouseExited(e); 203 TextButton::OnMouseExited(e);
185 } 204 }
186 205
187 void BrowserActionButton::PopupDidShow() { 206 void BrowserActionButton::SetButtonPushed() {
188 SetState(views::CustomButton::BS_PUSHED); 207 SetState(views::CustomButton::BS_PUSHED);
189 menu_visible_ = true; 208 menu_visible_ = true;
190 } 209 }
191 210
192 void BrowserActionButton::PopupDidHide() { 211 void BrowserActionButton::SetButtonNotPushed() {
193 SetState(views::CustomButton::BS_NORMAL); 212 SetState(views::CustomButton::BS_NORMAL);
194 menu_visible_ = false; 213 menu_visible_ = false;
195 } 214 }
196 215
197 216
198 //////////////////////////////////////////////////////////////////////////////// 217 ////////////////////////////////////////////////////////////////////////////////
199 // BrowserActionView 218 // BrowserActionView
200 219
201 BrowserActionView::BrowserActionView(Extension* extension, 220 BrowserActionView::BrowserActionView(Extension* extension,
202 BrowserActionsContainer* panel) 221 BrowserActionsContainer* panel)
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // Save these variables in local temporaries since destroying the popup 362 // Save these variables in local temporaries since destroying the popup
344 // calls BubbleLostFocus to be called, which will try to call HidePopup() 363 // calls BubbleLostFocus to be called, which will try to call HidePopup()
345 // again if popup_ is non-null. 364 // again if popup_ is non-null.
346 ExtensionPopup* closing_popup = popup_; 365 ExtensionPopup* closing_popup = popup_;
347 BrowserActionButton* closing_button = popup_button_; 366 BrowserActionButton* closing_button = popup_button_;
348 popup_ = NULL; 367 popup_ = NULL;
349 popup_button_ = NULL; 368 popup_button_ = NULL;
350 369
351 closing_popup->DetachFromBrowser(); 370 closing_popup->DetachFromBrowser();
352 delete closing_popup; 371 delete closing_popup;
353 closing_button->PopupDidHide(); 372 closing_button->SetButtonNotPushed();
354 return; 373 return;
355 } 374 }
356 } 375 }
357 376
358 void BrowserActionsContainer::TestExecuteBrowserAction(int index) { 377 void BrowserActionsContainer::TestExecuteBrowserAction(int index) {
359 BrowserActionButton* button = browser_action_views_[index]->button(); 378 BrowserActionButton* button = browser_action_views_[index]->button();
360 OnBrowserActionExecuted(button); 379 OnBrowserActionExecuted(button);
361 } 380 }
362 381
363 void BrowserActionsContainer::OnBrowserActionExecuted( 382 void BrowserActionsContainer::OnBrowserActionExecuted(
(...skipping 25 matching lines...) Expand all
389 BubbleBorder::TOP_LEFT : BubbleBorder::TOP_RIGHT; 408 BubbleBorder::TOP_LEFT : BubbleBorder::TOP_RIGHT;
390 popup_ = ExtensionPopup::Show(browser_action->popup_url(), 409 popup_ = ExtensionPopup::Show(browser_action->popup_url(),
391 toolbar_->browser(), 410 toolbar_->browser(),
392 toolbar_->browser()->profile(), 411 toolbar_->browser()->profile(),
393 frame_window, 412 frame_window,
394 rect, 413 rect,
395 arrowLocation, 414 arrowLocation,
396 true); // Activate the popup window. 415 true); // Activate the popup window.
397 popup_->set_delegate(this); 416 popup_->set_delegate(this);
398 popup_button_ = button; 417 popup_button_ = button;
399 popup_button_->PopupDidShow(); 418 popup_button_->SetButtonPushed();
400 return; 419 return;
401 } 420 }
402 421
403 // Otherwise, we send the action to the extension. 422 // Otherwise, we send the action to the extension.
404 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( 423 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted(
405 profile_, browser_action->extension_id(), toolbar_->browser()); 424 profile_, browser_action->extension_id(), toolbar_->browser());
406 } 425 }
407 426
408 gfx::Size BrowserActionsContainer::GetPreferredSize() { 427 gfx::Size BrowserActionsContainer::GetPreferredSize() {
409 if (browser_action_views_.empty()) 428 if (browser_action_views_.empty())
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 std::min(static_cast<int>(browser_action_views_.size()), 527 std::min(static_cast<int>(browser_action_views_.size()),
509 kMinimumNumberOfVisibleBrowserActions) * kButtonSize; 528 kMinimumNumberOfVisibleBrowserActions) * kButtonSize;
510 529
511 // Even if available_width is <= 0, we still return at least the |min_width|. 530 // Even if available_width is <= 0, we still return at least the |min_width|.
512 if (available_width <= 0) 531 if (available_width <= 0)
513 return min_width; 532 return min_width;
514 533
515 return std::max(min_width, available_width - available_width % kButtonSize + 534 return std::max(min_width, available_width - available_width % kButtonSize +
516 kHorizontalPadding * 2); 535 kHorizontalPadding * 2);
517 } 536 }
OLDNEW
« no previous file with comments | « chrome/browser/views/browser_actions_container.h ('k') | chrome/browser/views/extensions/extension_action_context_menu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698