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

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

Issue 501136: Merge 34812 - Add the rightclick context menu for Browser actions and Page... (Closed) Base URL: svn://chrome-svn/chrome/branches/249/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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 //////////////////////////////////////////////////////////////////////////////// 48 ////////////////////////////////////////////////////////////////////////////////
49 // BrowserActionButton 49 // BrowserActionButton
50 50
51 BrowserActionButton::BrowserActionButton(Extension* extension, 51 BrowserActionButton::BrowserActionButton(Extension* extension,
52 BrowserActionsContainer* panel) 52 BrowserActionsContainer* panel)
53 : MenuButton(this, L"", NULL, false), 53 : MenuButton(this, L"", NULL, false),
54 browser_action_(extension->browser_action()), 54 browser_action_(extension->browser_action()),
55 extension_(extension), 55 extension_(extension),
56 tracker_(NULL), 56 tracker_(NULL),
57 showing_context_menu_(false),
57 panel_(panel) { 58 panel_(panel) {
58 set_alignment(TextButton::ALIGN_CENTER); 59 set_alignment(TextButton::ALIGN_CENTER);
59 60
60 // No UpdateState() here because View heirarchy not setup yet. Our parent 61 // No UpdateState() here because View hierarchy not setup yet. Our parent
61 // should call UpdateState() after creation. 62 // should call UpdateState() after creation.
62 63
63 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, 64 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
64 Source<ExtensionAction>(browser_action_)); 65 Source<ExtensionAction>(browser_action_));
65 66
66 // The Browser Action API does not allow the default icon path to be changed 67 // The Browser Action API does not allow the default icon path to be changed
67 // at runtime, so we can load this now and cache it. 68 // at runtime, so we can load this now and cache it.
68 std::string relative_path = browser_action_->default_icon_path(); 69 std::string relative_path = browser_action_->default_icon_path();
69 if (relative_path.empty()) 70 if (relative_path.empty())
70 return; 71 return;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // The return value of this method is returned via OnMousePressed. 147 // The return value of this method is returned via OnMousePressed.
147 // We need to return false here since we're handing off focus to another 148 // We need to return false here since we're handing off focus to another
148 // widget/view, and true will grab it right back and try to send events 149 // widget/view, and true will grab it right back and try to send events
149 // to us. 150 // to us.
150 return false; 151 return false;
151 } 152 }
152 return true; 153 return true;
153 } 154 }
154 155
155 bool BrowserActionButton::OnMousePressed(const views::MouseEvent& e) { 156 bool BrowserActionButton::OnMousePressed(const views::MouseEvent& e) {
156 if (IsPopup()) 157 showing_context_menu_ = e.IsRightMouseButton();
158 if (showing_context_menu_) {
159 SetButtonPushed();
160
161 // Get the top left point of this button in screen coordinates.
162 gfx::Point point = gfx::Point(0, 0);
163 ConvertPointToScreen(this, &point);
164
165 // Make the menu appear below the button.
166 point.Offset(0, height());
167
168 if (!context_menu_.get())
169 context_menu_.reset(new ExtensionActionContextMenu());
170 context_menu_->Run(extension(), point);
171
172 SetButtonNotPushed();
173 return false;
174 } else if (IsPopup()) {
157 return MenuButton::OnMousePressed(e); 175 return MenuButton::OnMousePressed(e);
176 }
158 return TextButton::OnMousePressed(e); 177 return TextButton::OnMousePressed(e);
159 } 178 }
160 179
161 void BrowserActionButton::OnMouseReleased(const views::MouseEvent& e, 180 void BrowserActionButton::OnMouseReleased(const views::MouseEvent& e,
162 bool canceled) { 181 bool canceled) {
163 if (IsPopup()) { 182 if (IsPopup() || showing_context_menu_) {
164 // TODO(erikkay) this never actually gets called (probably because of the 183 // TODO(erikkay) this never actually gets called (probably because of the
165 // loss of focus). 184 // loss of focus).
166 MenuButton::OnMouseReleased(e, canceled); 185 MenuButton::OnMouseReleased(e, canceled);
167 } else { 186 } else {
168 TextButton::OnMouseReleased(e, canceled); 187 TextButton::OnMouseReleased(e, canceled);
169 } 188 }
170 } 189 }
171 190
172 bool BrowserActionButton::OnKeyReleased(const views::KeyEvent& e) { 191 bool BrowserActionButton::OnKeyReleased(const views::KeyEvent& e) {
173 if (IsPopup()) 192 if (IsPopup())
174 return MenuButton::OnKeyReleased(e); 193 return MenuButton::OnKeyReleased(e);
175 return TextButton::OnKeyReleased(e); 194 return TextButton::OnKeyReleased(e);
176 } 195 }
177 196
178 void BrowserActionButton::OnMouseExited(const views::MouseEvent& e) { 197 void BrowserActionButton::OnMouseExited(const views::MouseEvent& e) {
179 if (IsPopup()) 198 if (IsPopup() || showing_context_menu_)
180 MenuButton::OnMouseExited(e); 199 MenuButton::OnMouseExited(e);
181 else 200 else
182 TextButton::OnMouseExited(e); 201 TextButton::OnMouseExited(e);
183 } 202 }
184 203
185 void BrowserActionButton::PopupDidShow() { 204 void BrowserActionButton::SetButtonPushed() {
186 SetState(views::CustomButton::BS_PUSHED); 205 SetState(views::CustomButton::BS_PUSHED);
187 menu_visible_ = true; 206 menu_visible_ = true;
188 } 207 }
189 208
190 void BrowserActionButton::PopupDidHide() { 209 void BrowserActionButton::SetButtonNotPushed() {
191 SetState(views::CustomButton::BS_NORMAL); 210 SetState(views::CustomButton::BS_NORMAL);
192 menu_visible_ = false; 211 menu_visible_ = false;
193 } 212 }
194 213
195 214
196 //////////////////////////////////////////////////////////////////////////////// 215 ////////////////////////////////////////////////////////////////////////////////
197 // BrowserActionView 216 // BrowserActionView
198 217
199 BrowserActionView::BrowserActionView(Extension* extension, 218 BrowserActionView::BrowserActionView(Extension* extension,
200 BrowserActionsContainer* panel) 219 BrowserActionsContainer* panel)
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // Save these variables in local temporaries since destroying the popup 360 // Save these variables in local temporaries since destroying the popup
342 // calls BubbleLostFocus to be called, which will try to call HidePopup() 361 // calls BubbleLostFocus to be called, which will try to call HidePopup()
343 // again if popup_ is non-null. 362 // again if popup_ is non-null.
344 ExtensionPopup* closing_popup = popup_; 363 ExtensionPopup* closing_popup = popup_;
345 BrowserActionButton* closing_button = popup_button_; 364 BrowserActionButton* closing_button = popup_button_;
346 popup_ = NULL; 365 popup_ = NULL;
347 popup_button_ = NULL; 366 popup_button_ = NULL;
348 367
349 closing_popup->DetachFromBrowser(); 368 closing_popup->DetachFromBrowser();
350 delete closing_popup; 369 delete closing_popup;
351 closing_button->PopupDidHide(); 370 closing_button->SetButtonNotPushed();
352 return; 371 return;
353 } 372 }
354 } 373 }
355 374
356 void BrowserActionsContainer::TestExecuteBrowserAction(int index) { 375 void BrowserActionsContainer::TestExecuteBrowserAction(int index) {
357 BrowserActionButton* button = browser_action_views_[index]->button(); 376 BrowserActionButton* button = browser_action_views_[index]->button();
358 OnBrowserActionExecuted(button); 377 OnBrowserActionExecuted(button);
359 } 378 }
360 379
361 void BrowserActionsContainer::OnBrowserActionExecuted( 380 void BrowserActionsContainer::OnBrowserActionExecuted(
(...skipping 17 matching lines...) Expand all
379 View::ConvertPointToScreen(button, &origin); 398 View::ConvertPointToScreen(button, &origin);
380 gfx::Rect rect = button->bounds(); 399 gfx::Rect rect = button->bounds();
381 rect.set_x(origin.x()); 400 rect.set_x(origin.x());
382 rect.set_y(origin.y()); 401 rect.set_y(origin.y());
383 popup_ = ExtensionPopup::Show(browser_action->popup_url(), 402 popup_ = ExtensionPopup::Show(browser_action->popup_url(),
384 toolbar_->browser(), 403 toolbar_->browser(),
385 rect, 404 rect,
386 BubbleBorder::TOP_RIGHT); 405 BubbleBorder::TOP_RIGHT);
387 popup_->set_delegate(this); 406 popup_->set_delegate(this);
388 popup_button_ = button; 407 popup_button_ = button;
389 popup_button_->PopupDidShow(); 408 popup_button_->SetButtonPushed();
390 return; 409 return;
391 } 410 }
392 411
393 // Otherwise, we send the action to the extension. 412 // Otherwise, we send the action to the extension.
394 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( 413 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted(
395 profile_, browser_action->extension_id(), toolbar_->browser()); 414 profile_, browser_action->extension_id(), toolbar_->browser());
396 } 415 }
397 416
398 gfx::Size BrowserActionsContainer::GetPreferredSize() { 417 gfx::Size BrowserActionsContainer::GetPreferredSize() {
399 if (browser_action_views_.empty()) 418 if (browser_action_views_.empty())
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 std::min(static_cast<int>(browser_action_views_.size()), 503 std::min(static_cast<int>(browser_action_views_.size()),
485 kMinimumNumberOfVisibleBrowserActions) * kButtonSize; 504 kMinimumNumberOfVisibleBrowserActions) * kButtonSize;
486 505
487 // Even if available_width is <= 0, we still return at least the |min_width|. 506 // Even if available_width is <= 0, we still return at least the |min_width|.
488 if (available_width <= 0) 507 if (available_width <= 0)
489 return min_width; 508 return min_width;
490 509
491 return std::max(min_width, available_width - available_width % kButtonSize + 510 return std::max(min_width, available_width - available_width % kButtonSize +
492 kHorizontalPadding * 2); 511 kHorizontalPadding * 2);
493 } 512 }
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