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

Side by Side Diff: chrome/browser/views/location_bar/location_bar_view.cc

Issue 2817022: Small tweaks to improve toolbar keyboard accessibility: Put focus rects... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 6 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) 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/location_bar/location_bar_view.h" 5 #include "chrome/browser/views/location_bar/location_bar_view.h"
6 6
7 #if defined(OS_LINUX) 7 #if defined(OS_LINUX)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
11 #include "app/l10n_util.h"
sky 2010/06/21 20:55:32 after app/drag...
11 #include "app/drag_drop_types.h" 12 #include "app/drag_drop_types.h"
12 #include "app/resource_bundle.h" 13 #include "app/resource_bundle.h"
13 #include "app/theme_provider.h" 14 #include "app/theme_provider.h"
14 #include "chrome/app/chrome_dll_resource.h" 15 #include "chrome/app/chrome_dll_resource.h"
15 #include "chrome/browser/alternate_nav_url_fetcher.h" 16 #include "chrome/browser/alternate_nav_url_fetcher.h"
16 #include "chrome/browser/extensions/extension_browser_event_router.h" 17 #include "chrome/browser/extensions/extension_browser_event_router.h"
17 #include "chrome/browser/extensions/extensions_service.h" 18 #include "chrome/browser/extensions/extensions_service.h"
18 #include "chrome/browser/profile.h" 19 #include "chrome/browser/profile.h"
19 #include "chrome/browser/view_ids.h" 20 #include "chrome/browser/view_ids.h"
20 #include "chrome/browser/views/browser_dialogs.h" 21 #include "chrome/browser/views/browser_dialogs.h"
21 #include "chrome/browser/views/location_bar/content_setting_image_view.h" 22 #include "chrome/browser/views/location_bar/content_setting_image_view.h"
22 #include "chrome/browser/views/location_bar/ev_bubble_view.h" 23 #include "chrome/browser/views/location_bar/ev_bubble_view.h"
23 #include "chrome/browser/views/location_bar/keyword_hint_view.h" 24 #include "chrome/browser/views/location_bar/keyword_hint_view.h"
24 #include "chrome/browser/views/location_bar/location_icon_view.h" 25 #include "chrome/browser/views/location_bar/location_icon_view.h"
25 #include "chrome/browser/views/location_bar/page_action_image_view.h" 26 #include "chrome/browser/views/location_bar/page_action_image_view.h"
26 #include "chrome/browser/views/location_bar/page_action_with_badge_view.h" 27 #include "chrome/browser/views/location_bar/page_action_with_badge_view.h"
27 #include "chrome/browser/views/location_bar/selected_keyword_view.h" 28 #include "chrome/browser/views/location_bar/selected_keyword_view.h"
28 #include "chrome/browser/views/location_bar/star_view.h" 29 #include "chrome/browser/views/location_bar/star_view.h"
29 #include "gfx/canvas.h" 30 #include "gfx/canvas.h"
30 #include "gfx/color_utils.h" 31 #include "gfx/color_utils.h"
31 #include "gfx/skia_util.h" 32 #include "gfx/skia_util.h"
33 #include "grit/generated_resources.h"
32 #include "grit/theme_resources.h" 34 #include "grit/theme_resources.h"
33 #include "views/drag_utils.h" 35 #include "views/drag_utils.h"
34 36
35 #if defined(OS_WIN) 37 #if defined(OS_WIN)
36 #include "chrome/browser/views/first_run_bubble.h" 38 #include "chrome/browser/views/first_run_bubble.h"
37 #endif 39 #endif
38 40
39 using views::View; 41 using views::View;
40 42
41 // static 43 // static
42 const int LocationBarView::kVertMargin = 2; 44 const int LocationBarView::kVertMargin = 2;
43 const int LocationBarView::kEdgeThickness = 2; 45 const int LocationBarView::kEdgeThickness = 2;
44 const int LocationBarView::kItemPadding = 3; 46 const int LocationBarView::kItemPadding = 3;
47 const char LocationBarView::kViewClassName[] =
48 "browser/views/location_bar/LocationBarView";
45 49
46 // Convenience: Total space at the edges of the bar. 50 // Convenience: Total space at the edges of the bar.
47 const int kEdgePadding = 51 const int kEdgePadding =
48 LocationBarView::kEdgeThickness + LocationBarView::kItemPadding; 52 LocationBarView::kEdgeThickness + LocationBarView::kItemPadding;
49 53
50 // Padding before the start of a bubble. 54 // Padding before the start of a bubble.
51 static const int kBubblePadding = kEdgePadding - 1; 55 static const int kBubblePadding = kEdgePadding - 1;
52 56
53 // Padding between the location icon and the edit, if they're adjacent. 57 // Padding between the location icon and the edit, if they're adjacent.
54 static const int kLocationIconEditPadding = LocationBarView::kItemPadding - 1; 58 static const int kLocationIconEditPadding = LocationBarView::kItemPadding - 1;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 delegate_(delegate), 91 delegate_(delegate),
88 disposition_(CURRENT_TAB), 92 disposition_(CURRENT_TAB),
89 location_icon_view_(NULL), 93 location_icon_view_(NULL),
90 ev_bubble_view_(NULL), 94 ev_bubble_view_(NULL),
91 location_entry_view_(NULL), 95 location_entry_view_(NULL),
92 selected_keyword_view_(NULL), 96 selected_keyword_view_(NULL),
93 keyword_hint_view_(NULL), 97 keyword_hint_view_(NULL),
94 star_view_(NULL), 98 star_view_(NULL),
95 mode_(mode), 99 mode_(mode),
96 force_hidden_count_(0), 100 force_hidden_count_(0),
101 show_focus_rect_(false),
97 ALLOW_THIS_IN_INITIALIZER_LIST(first_run_bubble_(this)) { 102 ALLOW_THIS_IN_INITIALIZER_LIST(first_run_bubble_(this)) {
98 DCHECK(profile_); 103 DCHECK(profile_);
99 SetID(VIEW_ID_LOCATION_BAR); 104 SetID(VIEW_ID_LOCATION_BAR);
100 SetFocusable(true); 105 SetFocusable(true);
101 106
102 if (mode_ == NORMAL) 107 if (mode_ == NORMAL)
103 painter_.reset(new views::HorizontalPainter(kNormalModeBackgroundImages)); 108 painter_.reset(new views::HorizontalPainter(kNormalModeBackgroundImages));
104 } 109 }
105 110
106 LocationBarView::~LocationBarView() { 111 LocationBarView::~LocationBarView() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 gtk_widget_show_all(location_entry_->GetNativeView()); 153 gtk_widget_show_all(location_entry_->GetNativeView());
149 // Hide the widget. NativeViewHostGtk will make it visible again as 154 // Hide the widget. NativeViewHostGtk will make it visible again as
150 // necessary. 155 // necessary.
151 gtk_widget_hide(location_entry_->GetNativeView()); 156 gtk_widget_hide(location_entry_->GetNativeView());
152 #endif 157 #endif
153 location_entry_view_ = new views::NativeViewHost; 158 location_entry_view_ = new views::NativeViewHost;
154 location_entry_view_->SetID(VIEW_ID_AUTOCOMPLETE); 159 location_entry_view_->SetID(VIEW_ID_AUTOCOMPLETE);
155 AddChildView(location_entry_view_); 160 AddChildView(location_entry_view_);
156 location_entry_view_->set_focus_view(this); 161 location_entry_view_->set_focus_view(this);
157 location_entry_view_->Attach(location_entry_->GetNativeView()); 162 location_entry_view_->Attach(location_entry_->GetNativeView());
163 location_entry_view_->SetAccessibleName(
164 l10n_util::GetString(IDS_ACCNAME_LOCATION));
158 165
159 selected_keyword_view_ = 166 selected_keyword_view_ =
160 new SelectedKeywordView(kSelectedKeywordBackgroundImages, 167 new SelectedKeywordView(kSelectedKeywordBackgroundImages,
161 IDR_OMNIBOX_SEARCH, SK_ColorBLACK, profile_), 168 IDR_OMNIBOX_SEARCH, SK_ColorBLACK, profile_),
162 AddChildView(selected_keyword_view_); 169 AddChildView(selected_keyword_view_);
163 selected_keyword_view_->SetFont(font_); 170 selected_keyword_view_->SetFont(font_);
164 selected_keyword_view_->SetVisible(false); 171 selected_keyword_view_->SetVisible(false);
165 172
166 SkColor dimmed_text = GetColor(ToolbarModel::NONE, DEEMPHASIZED_TEXT); 173 SkColor dimmed_text = GetColor(ToolbarModel::NONE, DEEMPHASIZED_TEXT);
167 174
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 paint.setAntiAlias(true); 554 paint.setAntiAlias(true);
548 // The round corners of the omnibox match the round corners of the dropdown 555 // The round corners of the omnibox match the round corners of the dropdown
549 // below, and all our other bubbles. 556 // below, and all our other bubbles.
550 const SkScalar radius(SkIntToScalar(BubbleBorder::GetCornerRadius())); 557 const SkScalar radius(SkIntToScalar(BubbleBorder::GetCornerRadius()));
551 bounds.Inset(kEdgeThickness, 0); 558 bounds.Inset(kEdgeThickness, 0);
552 canvas->drawRoundRect(gfx::RectToSkRect(bounds), radius, radius, paint); 559 canvas->drawRoundRect(gfx::RectToSkRect(bounds), radius, radius, paint);
553 } else { 560 } else {
554 canvas->FillRectInt(color, bounds.x(), bounds.y(), bounds.width(), 561 canvas->FillRectInt(color, bounds.x(), bounds.y(), bounds.width(),
555 bounds.height()); 562 bounds.height());
556 } 563 }
564
565 if (show_focus_rect_ && HasFocus()) {
566 gfx::Rect r = location_entry_view_->bounds();
567 canvas->DrawFocusRect(r.x() - 1, r.y(), r.width() + 2, r.height());
sky 2010/06/21 20:55:32 Make sure this works for rtl.
568 }
557 } 569 }
558 570
559 void LocationBarView::VisibleBoundsInRootChanged() { 571 void LocationBarView::VisibleBoundsInRootChanged() {
560 location_entry_->ClosePopup(); 572 location_entry_->ClosePopup();
561 } 573 }
562 574
563 #if defined(OS_WIN) 575 #if defined(OS_WIN)
564 bool LocationBarView::OnMousePressed(const views::MouseEvent& event) { 576 bool LocationBarView::OnMousePressed(const views::MouseEvent& event) {
565 UINT msg; 577 UINT msg;
566 if (event.IsLeftMouseButton()) { 578 if (event.IsLeftMouseButton()) {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 // therefore we need to adjust the X coordinate so that bubble appears on the 844 // therefore we need to adjust the X coordinate so that bubble appears on the
833 // right hand side of the location bar. 845 // right hand side of the location bar.
834 if (base::i18n::IsRTL()) 846 if (base::i18n::IsRTL())
835 origin.set_x(width() - origin.x()); 847 origin.set_x(width() - origin.x());
836 views::View::ConvertPointToScreen(this, &origin); 848 views::View::ConvertPointToScreen(this, &origin);
837 FirstRunBubble::Show(profile_, GetWidget(), gfx::Rect(origin, gfx::Size()), 849 FirstRunBubble::Show(profile_, GetWidget(), gfx::Rect(origin, gfx::Size()),
838 BubbleBorder::TOP_LEFT, bubble_type); 850 BubbleBorder::TOP_LEFT, bubble_type);
839 #endif 851 #endif
840 } 852 }
841 853
854 std::string LocationBarView::GetClassName() const {
855 return kViewClassName;
856 }
857
842 bool LocationBarView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { 858 bool LocationBarView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
843 if (keyword_hint_view_->IsVisible() && 859 if (keyword_hint_view_->IsVisible() &&
844 views::FocusManager::IsTabTraversalKeyEvent(e)) { 860 views::FocusManager::IsTabTraversalKeyEvent(e)) {
845 // We want to receive tab key events when the hint is showing. 861 // We want to receive tab key events when the hint is showing.
846 return true; 862 return true;
847 } 863 }
848 864
849 #if defined(OS_WIN) 865 #if defined(OS_WIN)
850 return location_entry_->SkipDefaultKeyEventProcessing(e); 866 return location_entry_->SkipDefaultKeyEventProcessing(e);
851 #else 867 #else
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 page_action_views_[i]->image_view()->ExecuteAction(kLeftMouseButton, 1020 page_action_views_[i]->image_view()->ExecuteAction(kLeftMouseButton,
1005 false); // inspect_with_devtools 1021 false); // inspect_with_devtools
1006 return; 1022 return;
1007 } 1023 }
1008 ++current; 1024 ++current;
1009 } 1025 }
1010 } 1026 }
1011 1027
1012 NOTREACHED(); 1028 NOTREACHED();
1013 } 1029 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698