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

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

Issue 1105008: Allow Extensions to have MSAA information (Closed)
Patch Set: Created 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/l10n_util.h"
8 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
9 #include "app/slide_animation.h" 10 #include "app/slide_animation.h"
10 #include "base/stl_util-inl.h" 11 #include "base/stl_util-inl.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "chrome/browser/browser.h" 13 #include "chrome/browser/browser.h"
13 #include "chrome/browser/browser_theme_provider.h" 14 #include "chrome/browser/browser_theme_provider.h"
14 #include "chrome/browser/browser_window.h" 15 #include "chrome/browser/browser_window.h"
15 #include "chrome/browser/extensions/extension_browser_event_router.h" 16 #include "chrome/browser/extensions/extension_browser_event_router.h"
16 #include "chrome/browser/extensions/extension_host.h" 17 #include "chrome/browser/extensions/extension_host.h"
17 #include "chrome/browser/extensions/extensions_service.h" 18 #include "chrome/browser/extensions/extensions_service.h"
18 #include "chrome/browser/extensions/extension_tabs_module.h" 19 #include "chrome/browser/extensions/extension_tabs_module.h"
19 #include "chrome/browser/renderer_host/render_widget_host_view.h" 20 #include "chrome/browser/renderer_host/render_widget_host_view.h"
20 #include "chrome/browser/renderer_host/render_view_host.h" 21 #include "chrome/browser/renderer_host/render_view_host.h"
21 #include "chrome/browser/profile.h" 22 #include "chrome/browser/profile.h"
22 #include "chrome/browser/tab_contents/tab_contents.h" 23 #include "chrome/browser/tab_contents/tab_contents.h"
23 #include "chrome/browser/view_ids.h" 24 #include "chrome/browser/view_ids.h"
24 #include "chrome/browser/views/detachable_toolbar_view.h" 25 #include "chrome/browser/views/detachable_toolbar_view.h"
25 #include "chrome/browser/views/extensions/browser_action_drag_data.h" 26 #include "chrome/browser/views/extensions/browser_action_drag_data.h"
26 #include "chrome/browser/views/extensions/extension_popup.h" 27 #include "chrome/browser/views/extensions/extension_popup.h"
27 #include "chrome/common/notification_source.h" 28 #include "chrome/common/notification_source.h"
28 #include "chrome/common/notification_type.h" 29 #include "chrome/common/notification_type.h"
29 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
30 #include "grit/app_resources.h" 31 #include "grit/app_resources.h"
32 #include "grit/generated_resources.h"
31 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
32 #include "third_party/skia/include/core/SkTypeface.h" 34 #include "third_party/skia/include/core/SkTypeface.h"
33 #include "third_party/skia/include/effects/SkGradientShader.h" 35 #include "third_party/skia/include/effects/SkGradientShader.h"
34 #include "views/controls/button/menu_button.h" 36 #include "views/controls/button/menu_button.h"
35 #include "views/controls/button/text_button.h" 37 #include "views/controls/button/text_button.h"
36 #include "views/drag_utils.h" 38 #include "views/drag_utils.h"
37 #include "views/window/window.h" 39 #include "views/window/window.h"
38 40
39 #include "grit/theme_resources.h" 41 #include "grit/theme_resources.h"
40 42
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 int tab_id = panel_->GetCurrentTabId(); 156 int tab_id = panel_->GetCurrentTabId();
155 if (tab_id < 0) 157 if (tab_id < 0)
156 return; 158 return;
157 159
158 SkBitmap image = browser_action()->GetIcon(tab_id); 160 SkBitmap image = browser_action()->GetIcon(tab_id);
159 if (!image.isNull()) 161 if (!image.isNull())
160 SetIcon(image); 162 SetIcon(image);
161 else if (!default_icon_.isNull()) 163 else if (!default_icon_.isNull())
162 SetIcon(default_icon_); 164 SetIcon(default_icon_);
163 165
164 SetTooltipText(UTF8ToWide(browser_action()->GetTitle(tab_id))); 166 // If the browser action name is empty, show the extension name instead.
167 std::wstring name = UTF8ToWide(browser_action()->GetTitle(tab_id));
168 if (name.empty())
169 name = UTF8ToWide(extension()->name());
170 SetTooltipText(name);
171 SetAccessibleName(name);
165 GetParent()->SchedulePaint(); 172 GetParent()->SchedulePaint();
166 } 173 }
167 174
168 void BrowserActionButton::Observe(NotificationType type, 175 void BrowserActionButton::Observe(NotificationType type,
169 const NotificationSource& source, 176 const NotificationSource& source,
170 const NotificationDetails& details) { 177 const NotificationDetails& details) {
171 if (type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED) { 178 if (type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED) {
172 UpdateState(); 179 UpdateState();
173 // The browser action may have become visible/hidden so we need to make 180 // The browser action may have become visible/hidden so we need to make
174 // sure the state gets updated. 181 // sure the state gets updated.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 302
296 if (tab_id >= 0) { 303 if (tab_id >= 0) {
297 gfx::Rect bounds = 304 gfx::Rect bounds =
298 gfx::Rect(icon.width(), icon.height() + kControlVertOffset); 305 gfx::Rect(icon.width(), icon.height() + kControlVertOffset);
299 button_->extension()->browser_action()->PaintBadge(canvas, bounds, tab_id); 306 button_->extension()->browser_action()->PaintBadge(canvas, bounds, tab_id);
300 } 307 }
301 308
302 return canvas; 309 return canvas;
303 } 310 }
304 311
312 bool BrowserActionView::GetAccessibleRole(AccessibilityTypes::Role* role) {
313 DCHECK(role);
M-A Ruel 2010/03/23 00:36:01 drive-by: you should have removed the DCHECK and s
314 *role = AccessibilityTypes::ROLE_GROUPING;
tfarina (gmail-do not use) 2010/03/20 19:47:21 nit: could you add the following lines? if (!role)
315 return true;
316 }
317
318 bool BrowserActionView::GetAccessibleName(std::wstring* name) {
M-A Ruel 2010/03/23 00:36:01 Same.
319 DCHECK(name);
320 *name = l10n_util::GetString(IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION);
tfarina (gmail-do not use) 2010/03/20 19:47:21 nit: could you add the following lines? if (!name
321 return true;
322 }
323
305 void BrowserActionView::Layout() { 324 void BrowserActionView::Layout() {
306 button_->SetBounds(0, kControlVertOffset, width(), kButtonSize); 325 button_->SetBounds(0, kControlVertOffset, width(), kButtonSize);
307 } 326 }
308 327
309 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { 328 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) {
310 View::PaintChildren(canvas); 329 View::PaintChildren(canvas);
311 ExtensionAction* action = button()->browser_action(); 330 ExtensionAction* action = button()->browser_action();
312 int tab_id = panel_->GetCurrentTabId(); 331 int tab_id = panel_->GetCurrentTabId();
313 if (tab_id < 0) 332 if (tab_id < 0)
314 return; 333 return;
(...skipping 25 matching lines...) Expand all
340 359
341 ExtensionsService* extension_service = profile_->GetExtensionsService(); 360 ExtensionsService* extension_service = profile_->GetExtensionsService();
342 if (!extension_service) // The |extension_service| can be NULL in Incognito. 361 if (!extension_service) // The |extension_service| can be NULL in Incognito.
343 return; 362 return;
344 363
345 model_ = extension_service->toolbar_model(); 364 model_ = extension_service->toolbar_model();
346 model_->AddObserver(this); 365 model_->AddObserver(this);
347 366
348 resize_animation_.reset(new SlideAnimation(this)); 367 resize_animation_.reset(new SlideAnimation(this));
349 resize_gripper_ = new views::ResizeGripper(this); 368 resize_gripper_ = new views::ResizeGripper(this);
369 resize_gripper_->SetAccessibleName(
370 l10n_util::GetString(IDS_ACCNAME_SEPARATOR));
350 resize_gripper_->SetVisible(false); 371 resize_gripper_->SetVisible(false);
351 AddChildView(resize_gripper_); 372 AddChildView(resize_gripper_);
352 373
353 // TODO(glen): Come up with a new bitmap for the chevron. 374 // TODO(glen): Come up with a new bitmap for the chevron.
354 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 375 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
355 SkBitmap* chevron_image = rb.GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS); 376 SkBitmap* chevron_image = rb.GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS);
356 chevron_ = new views::MenuButton(NULL, std::wstring(), this, false); 377 chevron_ = new views::MenuButton(NULL, std::wstring(), this, false);
357 chevron_->SetVisible(false); 378 chevron_->SetVisible(false);
358 chevron_->SetIcon(*chevron_image); 379 chevron_->SetIcon(*chevron_image);
380 chevron_->SetAccessibleName(
381 l10n_util::GetString(IDS_ACCNAME_EXTENSIONS_CHEVRON));
359 // Chevron contains >> that should point left in LTR locales. 382 // Chevron contains >> that should point left in LTR locales.
360 chevron_->EnableCanvasFlippingForRTLUI(true); 383 chevron_->EnableCanvasFlippingForRTLUI(true);
361 AddChildView(chevron_); 384 AddChildView(chevron_);
362 385
363 int predefined_width = 386 int predefined_width =
364 profile_->GetPrefs()->GetInteger(prefs::kBrowserActionContainerWidth); 387 profile_->GetPrefs()->GetInteger(prefs::kBrowserActionContainerWidth);
365 if (predefined_width == 0) { 388 if (predefined_width == 0) {
366 // The width will never be 0 (due to container min size restriction) 389 // The width will never be 0 (due to container min size restriction)
367 // except when no width has been saved. So, in that case ask the model 390 // except when no width has been saved. So, in that case ask the model
368 // how many icons we'll show and set initial size to that. 391 // how many icons we'll show and set initial size to that.
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 797
775 if (profile_->IsOffTheRecord()) 798 if (profile_->IsOffTheRecord())
776 i = model_->IncognitoIndexToOriginal(i); 799 i = model_->IncognitoIndexToOriginal(i);
777 800
778 model_->MoveBrowserAction(dragging, i); 801 model_->MoveBrowserAction(dragging, i);
779 802
780 OnDragExited(); // Perform clean up after dragging. 803 OnDragExited(); // Perform clean up after dragging.
781 return DragDropTypes::DRAG_MOVE; 804 return DragDropTypes::DRAG_MOVE;
782 } 805 }
783 806
807 bool BrowserActionsContainer::GetAccessibleRole(
808 AccessibilityTypes::Role* role) {
809 DCHECK(role);
810 *role = AccessibilityTypes::ROLE_GROUPING;
tfarina (gmail-do not use) 2010/03/20 19:47:21 nit: could you add the following lines? if (!role)
811 return true;
812 }
813
814 bool BrowserActionsContainer::GetAccessibleName(std::wstring* name) {
815 DCHECK(name);
816 *name = l10n_util::GetString(IDS_ACCNAME_EXTENSIONS);
tfarina (gmail-do not use) 2010/03/20 19:47:21 nit: could you add the following lines? if (!name)
817 return !name->empty();
818 }
819
784 void BrowserActionsContainer::MoveBrowserAction( 820 void BrowserActionsContainer::MoveBrowserAction(
785 const std::string& extension_id, size_t new_index) { 821 const std::string& extension_id, size_t new_index) {
786 ExtensionsService* service = profile_->GetExtensionsService(); 822 ExtensionsService* service = profile_->GetExtensionsService();
787 Extension* extension = service->GetExtensionById(extension_id, false); 823 Extension* extension = service->GetExtensionById(extension_id, false);
788 model_->MoveBrowserAction(extension, new_index); 824 model_->MoveBrowserAction(extension, new_index);
789 SchedulePaint(); 825 SchedulePaint();
790 } 826 }
791 827
792 void BrowserActionsContainer::RunMenu(View* source, const gfx::Point& pt) { 828 void BrowserActionsContainer::RunMenu(View* source, const gfx::Point& pt) {
793 if (source == chevron_) { 829 if (source == chevron_) {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 popup_ = NULL; 1122 popup_ = NULL;
1087 popup_button_->SetButtonNotPushed(); 1123 popup_button_->SetButtonNotPushed();
1088 popup_button_ = NULL; 1124 popup_button_ = NULL;
1089 } 1125 }
1090 1126
1091 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { 1127 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) {
1092 // Only display incognito-enabled extensions while in incognito mode. 1128 // Only display incognito-enabled extensions while in incognito mode.
1093 return (!profile_->IsOffTheRecord() || 1129 return (!profile_->IsOffTheRecord() ||
1094 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); 1130 profile_->GetExtensionsService()->IsIncognitoEnabled(extension));
1095 } 1131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698