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

Side by Side Diff: chrome/browser/ui/views/location_bar/page_action_image_view.cc

Issue 6685069: Disambiguate OnMouseCaptureLost from OnMouseReleased, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address most TODOs and sync. Created 9 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
OLDNEW
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/location_bar/page_action_image_view.h" 5 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_list.h" 8 #include "chrome/browser/browser_list.h"
9 #include "chrome/browser/extensions/extension_browser_event_router.h" 9 #include "chrome/browser/extensions/extension_browser_event_router.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 inspect_with_devtools, 95 inspect_with_devtools,
96 this); // ExtensionPopup::Observer 96 this); // ExtensionPopup::Observer
97 } else { 97 } else {
98 ExtensionService* service = profile_->GetExtensionService(); 98 ExtensionService* service = profile_->GetExtensionService();
99 service->browser_event_router()->PageActionExecuted( 99 service->browser_event_router()->PageActionExecuted(
100 profile_, page_action_->extension_id(), page_action_->id(), 100 profile_, page_action_->extension_id(), page_action_->id(),
101 current_tab_id_, current_url_.spec(), button); 101 current_tab_id_, current_url_.spec(), button);
102 } 102 }
103 } 103 }
104 104
105 void PageActionImageView::GetAccessibleState(ui::AccessibleViewState* state) {
106 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
107 }
108
109 bool PageActionImageView::OnMousePressed(const views::MouseEvent& event) { 105 bool PageActionImageView::OnMousePressed(const views::MouseEvent& event) {
110 // We want to show the bubble on mouse release; that is the standard behavior 106 // We want to show the bubble on mouse release; that is the standard behavior
111 // for buttons. (Also, triggering on mouse press causes bugs like 107 // for buttons. (Also, triggering on mouse press causes bugs like
112 // http://crbug.com/33155.) 108 // http://crbug.com/33155.)
113 return true; 109 return true;
114 } 110 }
115 111
116 void PageActionImageView::OnMouseReleased(const views::MouseEvent& event, 112 void PageActionImageView::OnMouseReleased(const views::MouseEvent& event) {
117 bool canceled) { 113 if (!HitTest(event.location()))
118 if (canceled || !HitTest(event.location()))
119 return; 114 return;
120 115
121 int button = -1; 116 int button = -1;
122 if (event.IsLeftMouseButton()) { 117 if (event.IsLeftMouseButton()) {
123 button = 1; 118 button = 1;
124 } else if (event.IsMiddleMouseButton()) { 119 } else if (event.IsMiddleMouseButton()) {
125 button = 2; 120 button = 2;
126 } else if (event.IsRightMouseButton()) { 121 } else if (event.IsRightMouseButton()) {
127 // Get the top left point of this button in screen coordinates. 122 // Get the top left point of this button in screen coordinates.
128 gfx::Point menu_origin; 123 gfx::Point menu_origin;
129 ConvertPointToScreen(this, &menu_origin); 124 ConvertPointToScreen(this, &menu_origin);
130 // Make the menu appear below the button. 125 // Make the menu appear below the button.
131 menu_origin.Offset(0, height()); 126 menu_origin.Offset(0, height());
132 ShowContextMenu(menu_origin, true); 127 ShowContextMenu(menu_origin, true);
133 return; 128 return;
134 } 129 }
135 130
136 ExecuteAction(button, false); // inspect_with_devtools 131 ExecuteAction(button, false); // inspect_with_devtools
137 } 132 }
138 133
139 bool PageActionImageView::OnKeyPressed(const views::KeyEvent& e) { 134 bool PageActionImageView::OnKeyPressed(const views::KeyEvent& event) {
140 if (e.key_code() == ui::VKEY_SPACE || e.key_code() == ui::VKEY_RETURN) { 135 if (event.key_code() == ui::VKEY_SPACE ||
136 event.key_code() == ui::VKEY_RETURN) {
141 ExecuteAction(1, false); 137 ExecuteAction(1, false);
142 return true; 138 return true;
143 } 139 }
144 return false; 140 return false;
145 } 141 }
146 142
147 void PageActionImageView::ShowContextMenu(const gfx::Point& p, 143 void PageActionImageView::ShowContextMenu(const gfx::Point& p,
148 bool is_mouse_gesture) { 144 bool is_mouse_gesture) {
149 const Extension* extension = profile_->GetExtensionService()-> 145 const Extension* extension = profile_->GetExtensionService()->
150 GetExtensionById(page_action()->extension_id(), false); 146 GetExtensionById(page_action()->extension_id(), false);
151 if (!extension->ShowConfigureContextMenus()) 147 if (!extension->ShowConfigureContextMenus())
152 return; 148 return;
153 149
154 Browser* browser = BrowserView::GetBrowserViewForNativeWindow( 150 Browser* browser = BrowserView::GetBrowserViewForNativeWindow(
155 platform_util::GetTopLevel(GetWidget()->GetNativeView()))->browser(); 151 platform_util::GetTopLevel(GetWidget()->GetNativeView()))->browser();
156 context_menu_contents_ = 152 context_menu_contents_ =
157 new ExtensionContextMenuModel(extension, browser, this); 153 new ExtensionContextMenuModel(extension, browser, this);
158 context_menu_menu_.reset(new views::Menu2(context_menu_contents_.get())); 154 context_menu_menu_.reset(new views::Menu2(context_menu_contents_.get()));
159 context_menu_menu_->RunContextMenuAt(p); 155 context_menu_menu_->RunContextMenuAt(p);
160 } 156 }
161 157
158 void PageActionImageView::GetAccessibleState(ui::AccessibleViewState* state) {
159 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
160 }
161
162 void PageActionImageView::OnImageLoaded( 162 void PageActionImageView::OnImageLoaded(
163 SkBitmap* image, const ExtensionResource& resource, int index) { 163 SkBitmap* image, const ExtensionResource& resource, int index) {
164 // We loaded icons()->size() icons, plus one extra if the page action had 164 // We loaded icons()->size() icons, plus one extra if the page action had
165 // a default icon. 165 // a default icon.
166 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); 166 int total_icons = static_cast<int>(page_action_->icon_paths()->size());
167 if (!page_action_->default_icon_path().empty()) 167 if (!page_action_->default_icon_path().empty())
168 total_icons++; 168 total_icons++;
169 DCHECK(index < total_icons); 169 DCHECK(index < total_icons);
170 170
171 // Map the index of the loaded image back to its name. If we ever get an 171 // Map the index of the loaded image back to its name. If we ever get an
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 void PageActionImageView::ExtensionPopupIsClosing(ExtensionPopup* popup) { 237 void PageActionImageView::ExtensionPopupIsClosing(ExtensionPopup* popup) {
238 DCHECK_EQ(popup_, popup); 238 DCHECK_EQ(popup_, popup);
239 // ExtensionPopup is ref-counted, so we don't need to delete it. 239 // ExtensionPopup is ref-counted, so we don't need to delete it.
240 popup_ = NULL; 240 popup_ = NULL;
241 } 241 }
242 242
243 void PageActionImageView::HidePopup() { 243 void PageActionImageView::HidePopup() {
244 if (popup_) 244 if (popup_)
245 popup_->Close(); 245 popup_->Close();
246 } 246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698