OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/toolbar_action_view.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 wants_to_run_border_->Paint(*this, canvas); | 130 wants_to_run_border_->Paint(*this, canvas); |
131 } | 131 } |
132 | 132 |
133 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { | 133 void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) { |
134 views::MenuButton::GetAccessibleState(state); | 134 views::MenuButton::GetAccessibleState(state); |
135 state->role = ui::AX_ROLE_BUTTON; | 135 state->role = ui::AX_ROLE_BUTTON; |
136 } | 136 } |
137 | 137 |
138 void ToolbarActionView::ButtonPressed(views::Button* sender, | 138 void ToolbarActionView::ButtonPressed(views::Button* sender, |
139 const ui::Event& event) { | 139 const ui::Event& event) { |
140 view_controller_->ExecuteAction(true); | 140 gfx::Point menu_point; |
| 141 ui::MenuSourceType type = ui::MENU_SOURCE_NONE; |
| 142 if (event.IsMouseEvent()) { |
| 143 menu_point = static_cast<const ui::MouseEvent&>(event).location(); |
| 144 type = ui::MENU_SOURCE_MOUSE; |
| 145 } else if (event.IsKeyEvent()) { |
| 146 menu_point = GetKeyboardContextMenuLocation(); |
| 147 type = ui::MENU_SOURCE_KEYBOARD; |
| 148 } else if (event.IsGestureEvent()) { |
| 149 menu_point = static_cast<const ui::GestureEvent&>(event).location(); |
| 150 type = ui::MENU_SOURCE_TOUCH; |
| 151 } |
| 152 |
| 153 HandleActivation(menu_point, type); |
141 } | 154 } |
142 | 155 |
143 void ToolbarActionView::UpdateState() { | 156 void ToolbarActionView::UpdateState() { |
144 content::WebContents* web_contents = GetCurrentWebContents(); | 157 content::WebContents* web_contents = GetCurrentWebContents(); |
145 if (SessionTabHelper::IdForTab(web_contents) < 0) | 158 if (SessionTabHelper::IdForTab(web_contents) < 0) |
146 return; | 159 return; |
147 | 160 |
148 if (!view_controller_->IsEnabled(web_contents)) | 161 if (!view_controller_->IsEnabled(web_contents) && |
149 SetState(views::CustomButton::STATE_DISABLED); | 162 !view_controller_->DisabledClickOpensMenu()) { |
150 else if (state() == views::CustomButton::STATE_DISABLED) | 163 SetState(views::CustomButton::STATE_DISABLED); |
| 164 } else if (state() == views::CustomButton::STATE_DISABLED) { |
151 SetState(views::CustomButton::STATE_NORMAL); | 165 SetState(views::CustomButton::STATE_NORMAL); |
| 166 } |
152 | 167 |
153 wants_to_run_ = view_controller_->WantsToRun(web_contents); | 168 wants_to_run_ = view_controller_->WantsToRun(web_contents); |
154 | 169 |
155 gfx::ImageSkia icon( | 170 gfx::ImageSkia icon( |
156 view_controller_->GetIcon(web_contents, | 171 view_controller_->GetIcon(web_contents, |
157 GetPreferredSize()).AsImageSkia()); | 172 GetPreferredSize()).AsImageSkia()); |
158 | 173 |
159 if (!icon.isNull()) { | 174 if (!icon.isNull()) { |
160 ThemeService* theme = ThemeServiceFactory::GetForProfile(profile_); | 175 ThemeService* theme = ThemeServiceFactory::GetForProfile(profile_); |
161 | 176 |
(...skipping 13 matching lines...) Expand all Loading... |
175 const content::NotificationSource& source, | 190 const content::NotificationSource& source, |
176 const content::NotificationDetails& details) { | 191 const content::NotificationDetails& details) { |
177 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); | 192 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); |
178 UpdateState(); | 193 UpdateState(); |
179 } | 194 } |
180 | 195 |
181 bool ToolbarActionView::Activate() { | 196 bool ToolbarActionView::Activate() { |
182 if (!view_controller_->HasPopup(GetCurrentWebContents())) | 197 if (!view_controller_->HasPopup(GetCurrentWebContents())) |
183 return true; | 198 return true; |
184 | 199 |
185 view_controller_->ExecuteAction(true); | 200 // Unfortunately, we don't get any of the event points for this call. Since |
| 201 // these are only used for showing a context menu when an action is disabled, |
| 202 // it's not that big a deal. Fake it. |
| 203 // TODO(devlin): This could obviously be improved. |
| 204 HandleActivation(GetKeyboardContextMenuLocation(), ui::MENU_SOURCE_KEYBOARD); |
186 | 205 |
187 // TODO(erikkay): Run a nested modal loop while the mouse is down to | 206 // TODO(erikkay): Run a nested modal loop while the mouse is down to |
188 // enable menu-like drag-select behavior. | 207 // enable menu-like drag-select behavior. |
189 | 208 |
190 // The return value of this method is returned via OnMousePressed. | 209 // The return value of this method is returned via OnMousePressed. |
191 // We need to return false here since we're handing off focus to another | 210 // We need to return false here since we're handing off focus to another |
192 // widget/view, and true will grab it right back and try to send events | 211 // widget/view, and true will grab it right back and try to send events |
193 // to us. | 212 // to us. |
194 return false; | 213 return false; |
195 } | 214 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 if (menu_controller->in_nested_run()) { | 393 if (menu_controller->in_nested_run()) { |
375 // There is another menu showing. Close the outermost menu (since we are | 394 // There is another menu showing. Close the outermost menu (since we are |
376 // shown in the same menu, we don't want to close the whole thing). | 395 // shown in the same menu, we don't want to close the whole thing). |
377 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); | 396 menu_controller->Cancel(views::MenuController::EXIT_OUTERMOST); |
378 return true; | 397 return true; |
379 } | 398 } |
380 } | 399 } |
381 | 400 |
382 return false; | 401 return false; |
383 } | 402 } |
| 403 |
| 404 void ToolbarActionView::HandleActivation(const gfx::Point& menu_point, |
| 405 ui::MenuSourceType source_type) { |
| 406 if (!view_controller_->IsEnabled(GetCurrentWebContents())) { |
| 407 // We should only get a button pressed event with a non-enabled action if |
| 408 // the left-click behavior should open the menu. |
| 409 DCHECK(view_controller_->DisabledClickOpensMenu()); |
| 410 context_menu_controller()->ShowContextMenuForView( |
| 411 this, menu_point, source_type); |
| 412 } else { |
| 413 view_controller_->ExecuteAction(true); |
| 414 } |
| 415 } |
OLD | NEW |