| OLD | NEW |
| 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/toolbar_view.h" | 5 #include "chrome/browser/views/toolbar_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/drag_drop_types.h" | 9 #include "app/drag_drop_types.h" |
| 10 #include "app/gfx/canvas.h" | 10 #include "app/gfx/canvas.h" |
| 11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "app/os_exchange_data.h" | 12 #include "app/os_exchange_data.h" |
| 13 #include "app/resource_bundle.h" | 13 #include "app/resource_bundle.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/keyboard_codes.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 17 #include "chrome/app/chrome_dll_resource.h" | 18 #include "chrome/app/chrome_dll_resource.h" |
| 18 #include "chrome/browser/back_forward_menu_model_views.h" | 19 #include "chrome/browser/back_forward_menu_model_views.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_model.h" | 20 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 20 #include "chrome/browser/browser.h" | 21 #include "chrome/browser/browser.h" |
| 21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/browser_window.h" | 23 #include "chrome/browser/browser_window.h" |
| 23 #include "chrome/browser/character_encoding.h" | 24 #include "chrome/browser/character_encoding.h" |
| 24 #include "chrome/browser/encoding_menu_controller.h" | 25 #include "chrome/browser/encoding_menu_controller.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 #include "chrome/common/notification_service.h" | 40 #include "chrome/common/notification_service.h" |
| 40 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
| 41 #include "chrome/common/pref_service.h" | 42 #include "chrome/common/pref_service.h" |
| 42 #include "grit/chromium_strings.h" | 43 #include "grit/chromium_strings.h" |
| 43 #include "grit/generated_resources.h" | 44 #include "grit/generated_resources.h" |
| 44 #include "grit/theme_resources.h" | 45 #include "grit/theme_resources.h" |
| 45 #include "net/base/net_util.h" | 46 #include "net/base/net_util.h" |
| 46 #include "views/background.h" | 47 #include "views/background.h" |
| 47 #include "views/controls/button/button_dropdown.h" | 48 #include "views/controls/button/button_dropdown.h" |
| 48 #include "views/controls/label.h" | 49 #include "views/controls/label.h" |
| 50 #include "views/widget/tooltip_manager.h" |
| 49 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 50 #include "views/drag_utils.h" | 52 #include "views/drag_utils.h" |
| 51 #include "views/widget/tooltip_manager.h" | |
| 52 #endif | 53 #endif |
| 53 #include "views/window/non_client_view.h" | 54 #include "views/window/non_client_view.h" |
| 54 #include "views/window/window.h" | 55 #include "views/window/window.h" |
| 55 | 56 |
| 56 static const int kControlHorizOffset = 4; | 57 static const int kControlHorizOffset = 4; |
| 57 static const int kControlVertOffset = 6; | 58 static const int kControlVertOffset = 6; |
| 58 static const int kControlIndent = 3; | 59 static const int kControlIndent = 3; |
| 59 static const int kStatusBubbleWidth = 480; | 60 static const int kStatusBubbleWidth = 480; |
| 60 | 61 |
| 61 // Separation between the location bar and the menus. | 62 // Separation between the location bar and the menus. |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 LoadCenterStackImages(); | 578 LoadCenterStackImages(); |
| 578 LoadRightSideControlsImages(); | 579 LoadRightSideControlsImages(); |
| 579 } | 580 } |
| 580 | 581 |
| 581 void ToolbarView::ShowContextMenu(int x, int y, bool is_mouse_gesture) { | 582 void ToolbarView::ShowContextMenu(int x, int y, bool is_mouse_gesture) { |
| 582 if (acc_focused_view_) | 583 if (acc_focused_view_) |
| 583 acc_focused_view_->ShowContextMenu(x, y, is_mouse_gesture); | 584 acc_focused_view_->ShowContextMenu(x, y, is_mouse_gesture); |
| 584 } | 585 } |
| 585 | 586 |
| 586 void ToolbarView::DidGainFocus() { | 587 void ToolbarView::DidGainFocus() { |
| 587 #if defined(OS_WIN) | |
| 588 // Check to see if MSAA focus should be restored to previously focused button, | 588 // Check to see if MSAA focus should be restored to previously focused button, |
| 589 // and if button is an enabled, visibled child of toolbar. | 589 // and if button is an enabled, visibled child of toolbar. |
| 590 if (!acc_focused_view_ || | 590 if (!acc_focused_view_ || |
| 591 (acc_focused_view_->GetParent()->GetID() != VIEW_ID_TOOLBAR) || | 591 (acc_focused_view_->GetParent()->GetID() != VIEW_ID_TOOLBAR) || |
| 592 !acc_focused_view_->IsEnabled() || | 592 !acc_focused_view_->IsEnabled() || |
| 593 !acc_focused_view_->IsVisible()) { | 593 !acc_focused_view_->IsVisible()) { |
| 594 // Find first accessible child (-1 to start search at parent). | 594 // Find first accessible child (-1 to start search at parent). |
| 595 int first_acc_child = GetNextAccessibleViewIndex(-1, false); | 595 int first_acc_child = GetNextAccessibleViewIndex(-1, false); |
| 596 | 596 |
| 597 // No buttons enabled or visible. | 597 // No buttons enabled or visible. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 609 acc_focused_view_->SetHotTracked(true); | 609 acc_focused_view_->SetHotTracked(true); |
| 610 | 610 |
| 611 // Show the tooltip for the view that got the focus. | 611 // Show the tooltip for the view that got the focus. |
| 612 if (GetWidget()->GetTooltipManager()) | 612 if (GetWidget()->GetTooltipManager()) |
| 613 GetWidget()->GetTooltipManager()->ShowKeyboardTooltip(acc_focused_view_); | 613 GetWidget()->GetTooltipManager()->ShowKeyboardTooltip(acc_focused_view_); |
| 614 | 614 |
| 615 // Update focused_view with MSAA-adjusted child id. | 615 // Update focused_view with MSAA-adjusted child id. |
| 616 view_index = acc_focused_view_->GetID(); | 616 view_index = acc_focused_view_->GetID(); |
| 617 } | 617 } |
| 618 | 618 |
| 619 #if defined(OS_WIN) |
| 619 gfx::NativeView wnd = GetWidget()->GetNativeView(); | 620 gfx::NativeView wnd = GetWidget()->GetNativeView(); |
| 620 | 621 |
| 621 // Notify Access Technology that there was a change in keyboard focus. | 622 // Notify Access Technology that there was a change in keyboard focus. |
| 622 ::NotifyWinEvent(EVENT_OBJECT_FOCUS, wnd, OBJID_CLIENT, | 623 ::NotifyWinEvent(EVENT_OBJECT_FOCUS, wnd, OBJID_CLIENT, |
| 623 static_cast<LONG>(view_index)); | 624 static_cast<LONG>(view_index)); |
| 624 #else | 625 #else |
| 625 // TODO(port): deal with toolbar a11y focus. | 626 // TODO(port): deal with toolbar a11y focus. |
| 626 NOTIMPLEMENTED(); | 627 NOTIMPLEMENTED(); |
| 627 #endif | 628 #endif |
| 628 } | 629 } |
| 629 | 630 |
| 630 void ToolbarView::WillLoseFocus() { | 631 void ToolbarView::WillLoseFocus() { |
| 631 #if defined(OS_WIN) | |
| 632 if (acc_focused_view_) { | 632 if (acc_focused_view_) { |
| 633 // Resetting focus state. | 633 // Resetting focus state. |
| 634 acc_focused_view_->SetHotTracked(false); | 634 acc_focused_view_->SetHotTracked(false); |
| 635 } | 635 } |
| 636 // Any tooltips that are active should be hidden when toolbar loses focus. | 636 // Any tooltips that are active should be hidden when toolbar loses focus. |
| 637 if (GetWidget() && GetWidget()->GetTooltipManager()) | 637 if (GetWidget() && GetWidget()->GetTooltipManager()) |
| 638 GetWidget()->GetTooltipManager()->HideKeyboardTooltip(); | 638 GetWidget()->GetTooltipManager()->HideKeyboardTooltip(); |
| 639 #else | |
| 640 // TODO(port): deal with toolbar a11y focus. | |
| 641 NOTIMPLEMENTED(); | |
| 642 #endif | |
| 643 } | 639 } |
| 644 | 640 |
| 645 bool ToolbarView::OnKeyPressed(const views::KeyEvent& e) { | 641 bool ToolbarView::OnKeyPressed(const views::KeyEvent& e) { |
| 646 #if defined(OS_WIN) | |
| 647 // Paranoia check, button should be initialized upon toolbar gaining focus. | 642 // Paranoia check, button should be initialized upon toolbar gaining focus. |
| 648 if (!acc_focused_view_) | 643 if (!acc_focused_view_) |
| 649 return false; | 644 return false; |
| 650 | 645 |
| 651 int focused_view = GetChildIndex(acc_focused_view_); | 646 int focused_view = GetChildIndex(acc_focused_view_); |
| 652 int next_view = focused_view; | 647 int next_view = focused_view; |
| 653 | 648 |
| 654 switch (e.GetCharacter()) { | 649 switch (e.GetCharacter()) { |
| 655 case VK_LEFT: | 650 case base::VKEY_LEFT: |
| 656 next_view = GetNextAccessibleViewIndex(focused_view, true); | 651 next_view = GetNextAccessibleViewIndex(focused_view, true); |
| 657 break; | 652 break; |
| 658 case VK_RIGHT: | 653 case base::VKEY_RIGHT: |
| 659 next_view = GetNextAccessibleViewIndex(focused_view, false); | 654 next_view = GetNextAccessibleViewIndex(focused_view, false); |
| 660 break; | 655 break; |
| 661 case VK_DOWN: | 656 case base::VKEY_DOWN: |
| 662 case VK_RETURN: | 657 case base::VKEY_RETURN: |
| 663 // VK_SPACE is already handled by the default case. | 658 // VKEY_SPACE is already handled by the default case. |
| 664 if (acc_focused_view_->GetID() == VIEW_ID_PAGE_MENU || | 659 if (acc_focused_view_->GetID() == VIEW_ID_PAGE_MENU || |
| 665 acc_focused_view_->GetID() == VIEW_ID_APP_MENU) { | 660 acc_focused_view_->GetID() == VIEW_ID_APP_MENU) { |
| 666 // If a menu button in toolbar is activated and its menu is displayed, | 661 // If a menu button in toolbar is activated and its menu is displayed, |
| 667 // then active tooltip should be hidden. | 662 // then active tooltip should be hidden. |
| 668 if (GetWidget()->GetTooltipManager()) | 663 if (GetWidget()->GetTooltipManager()) |
| 669 GetWidget()->GetTooltipManager()->HideKeyboardTooltip(); | 664 GetWidget()->GetTooltipManager()->HideKeyboardTooltip(); |
| 670 // Safe to cast, given to above view id check. | 665 // Safe to cast, given to above view id check. |
| 671 static_cast<views::MenuButton*>(acc_focused_view_)->Activate(); | 666 static_cast<views::MenuButton*>(acc_focused_view_)->Activate(); |
| 672 if (!acc_focused_view_) { | 667 if (!acc_focused_view_) { |
| 673 // Activate triggered a focus change, don't try to change focus. | 668 // Activate triggered a focus change, don't try to change focus. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 690 if (next_view != focused_view) { | 685 if (next_view != focused_view) { |
| 691 // Remove hot-tracking from old focused button. | 686 // Remove hot-tracking from old focused button. |
| 692 acc_focused_view_->SetHotTracked(false); | 687 acc_focused_view_->SetHotTracked(false); |
| 693 | 688 |
| 694 // All is well, update the focused child member variable. | 689 // All is well, update the focused child member variable. |
| 695 acc_focused_view_ = GetChildViewAt(next_view); | 690 acc_focused_view_ = GetChildViewAt(next_view); |
| 696 | 691 |
| 697 // Hot-track new focused button. | 692 // Hot-track new focused button. |
| 698 acc_focused_view_->SetHotTracked(true); | 693 acc_focused_view_->SetHotTracked(true); |
| 699 | 694 |
| 700 // Retrieve information to generate an MSAA focus event. | |
| 701 int view_id = acc_focused_view_->GetID(); | |
| 702 gfx::NativeView wnd = GetWidget()->GetNativeView(); | |
| 703 | |
| 704 // Show the tooltip for the view that got the focus. | 695 // Show the tooltip for the view that got the focus. |
| 705 if (GetWidget()->GetTooltipManager()) { | 696 if (GetWidget()->GetTooltipManager()) { |
| 706 GetWidget()->GetTooltipManager()-> | 697 GetWidget()->GetTooltipManager()-> |
| 707 ShowKeyboardTooltip(GetChildViewAt(next_view)); | 698 ShowKeyboardTooltip(GetChildViewAt(next_view)); |
| 708 } | 699 } |
| 700 #if defined(OS_WIN) |
| 701 // Retrieve information to generate an MSAA focus event. |
| 702 gfx::NativeView wnd = GetWidget()->GetNativeView(); |
| 703 int view_id = acc_focused_view_->GetID(); |
| 709 // Notify Access Technology that there was a change in keyboard focus. | 704 // Notify Access Technology that there was a change in keyboard focus. |
| 710 ::NotifyWinEvent(EVENT_OBJECT_FOCUS, wnd, OBJID_CLIENT, | 705 ::NotifyWinEvent(EVENT_OBJECT_FOCUS, wnd, OBJID_CLIENT, |
| 711 static_cast<LONG>(view_id)); | 706 static_cast<LONG>(view_id)); |
| 707 #else |
| 708 NOTIMPLEMENTED(); |
| 709 #endif |
| 712 return true; | 710 return true; |
| 713 } | 711 } |
| 714 #else | |
| 715 // TODO(port): deal with toolbar a11y focus. | |
| 716 NOTIMPLEMENTED(); | |
| 717 #endif | |
| 718 return false; | 712 return false; |
| 719 } | 713 } |
| 720 | 714 |
| 721 bool ToolbarView::OnKeyReleased(const views::KeyEvent& e) { | 715 bool ToolbarView::OnKeyReleased(const views::KeyEvent& e) { |
| 722 // Paranoia check, button should be initialized upon toolbar gaining focus. | 716 // Paranoia check, button should be initialized upon toolbar gaining focus. |
| 723 if (!acc_focused_view_) | 717 if (!acc_focused_view_) |
| 724 return false; | 718 return false; |
| 725 | 719 |
| 726 // Have keys be handled by the views themselves. | 720 // Have keys be handled by the views themselves. |
| 727 return acc_focused_view_->OnKeyReleased(e); | 721 return acc_focused_view_->OnKeyReleased(e); |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 app_menu_contents_->AddItem(IDC_ABOUT, | 1093 app_menu_contents_->AddItem(IDC_ABOUT, |
| 1100 l10n_util::GetStringFUTF16( | 1094 l10n_util::GetStringFUTF16( |
| 1101 IDS_ABOUT, | 1095 IDS_ABOUT, |
| 1102 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 1096 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 1103 app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); | 1097 app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); |
| 1104 app_menu_contents_->AddSeparator(); | 1098 app_menu_contents_->AddSeparator(); |
| 1105 app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT); | 1099 app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT); |
| 1106 | 1100 |
| 1107 app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get())); | 1101 app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get())); |
| 1108 } | 1102 } |
| OLD | NEW |