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

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

Issue 21696003: views/location_bar: Eliminate TouchableLocationBarView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 7 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 26 matching lines...) Expand all
37 #include "chrome/browser/ui/view_ids.h" 37 #include "chrome/browser/ui/view_ids.h"
38 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h" 38 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h"
39 #include "chrome/browser/ui/views/browser_dialogs.h" 39 #include "chrome/browser/ui/views/browser_dialogs.h"
40 #include "chrome/browser/ui/views/extensions/extension_popup.h" 40 #include "chrome/browser/ui/views/extensions/extension_popup.h"
41 #include "chrome/browser/ui/views/location_bar/autofill_credit_card_view.h" 41 #include "chrome/browser/ui/views/location_bar/autofill_credit_card_view.h"
42 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" 42 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
45 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" 45 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h"
46 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 46 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
47 #include "chrome/browser/ui/views/location_bar/mic_search_view.h"
48 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" 47 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h"
49 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 48 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
50 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" 49 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h"
51 #include "chrome/browser/ui/views/location_bar/script_bubble_icon_view.h" 50 #include "chrome/browser/ui/views/location_bar/script_bubble_icon_view.h"
52 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" 51 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
53 #include "chrome/browser/ui/views/location_bar/star_view.h" 52 #include "chrome/browser/ui/views/location_bar/star_view.h"
54 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" 53 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
55 #include "chrome/browser/ui/views/location_bar/zoom_view.h" 54 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
56 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 55 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
57 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" 56 #include "chrome/browser/ui/views/omnibox/omnibox_views.h"
(...skipping 14 matching lines...) Expand all
72 #include "ui/base/theme_provider.h" 71 #include "ui/base/theme_provider.h"
73 #include "ui/gfx/canvas.h" 72 #include "ui/gfx/canvas.h"
74 #include "ui/gfx/color_utils.h" 73 #include "ui/gfx/color_utils.h"
75 #include "ui/gfx/image/image.h" 74 #include "ui/gfx/image/image.h"
76 #include "ui/gfx/image/image_skia_operations.h" 75 #include "ui/gfx/image/image_skia_operations.h"
77 #include "ui/gfx/skia_util.h" 76 #include "ui/gfx/skia_util.h"
78 #include "ui/native_theme/native_theme.h" 77 #include "ui/native_theme/native_theme.h"
79 #include "ui/views/background.h" 78 #include "ui/views/background.h"
80 #include "ui/views/border.h" 79 #include "ui/views/border.h"
81 #include "ui/views/button_drag_utils.h" 80 #include "ui/views/button_drag_utils.h"
81 #include "ui/views/controls/button/image_button.h"
82 #include "ui/views/controls/label.h" 82 #include "ui/views/controls/label.h"
83 #include "ui/views/controls/textfield/textfield.h" 83 #include "ui/views/controls/textfield/textfield.h"
84 #include "ui/views/widget/widget.h" 84 #include "ui/views/widget/widget.h"
85 #include "ui/views/window/non_client_view.h" 85 #include "ui/views/window/non_client_view.h"
86 86
87 #if defined(OS_WIN) 87 #if defined(OS_WIN)
88 #include "base/win/scoped_hdc.h" 88 #include "base/win/scoped_hdc.h"
89 #include "base/win/scoped_select_object.h" 89 #include "base/win/scoped_select_object.h"
90 #include "ui/native_theme/native_theme_win.h" 90 #include "ui/native_theme/native_theme_win.h"
91 #endif 91 #endif
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 browser_->search_model()->AddObserver(this); 220 browser_->search_model()->AddObserver(this);
221 } 221 }
222 222
223 LocationBarView::~LocationBarView() { 223 LocationBarView::~LocationBarView() {
224 if (template_url_service_) 224 if (template_url_service_)
225 template_url_service_->RemoveObserver(this); 225 template_url_service_->RemoveObserver(this);
226 if (browser_) 226 if (browser_)
227 browser_->search_model()->RemoveObserver(this); 227 browser_->search_model()->RemoveObserver(this);
228 } 228 }
229 229
230 // static
231 void LocationBarView::InitTouchableLocationBarView(views::View* view) {
232 int horizontal_padding = GetBuiltInHorizontalPaddingForChildViews();
233 if (horizontal_padding != 0) {
234 view->set_border(views::Border::CreateEmptyBorder(
235 3, horizontal_padding, 3, horizontal_padding));
236 }
237 }
238
230 void LocationBarView::Init() { 239 void LocationBarView::Init() {
231 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're 240 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're
232 // not prepared for that. 241 // not prepared for that.
233 DCHECK(GetWidget()); 242 DCHECK(GetWidget());
234 243
235 location_icon_view_ = new LocationIconView(this); 244 location_icon_view_ = new LocationIconView(this);
236 location_icon_view_->set_drag_controller(this); 245 location_icon_view_->set_drag_controller(this);
237 AddChildView(location_icon_view_); 246 AddChildView(location_icon_view_);
238 247
239 // Determine the main font. 248 // Determine the main font.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); 316 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT));
308 suggested_text_view_->SetVisible(false); 317 suggested_text_view_->SetVisible(false);
309 AddChildView(suggested_text_view_); 318 AddChildView(suggested_text_view_);
310 319
311 keyword_hint_view_ = new KeywordHintView( 320 keyword_hint_view_ = new KeywordHintView(
312 profile_, font, font_y_offset, 321 profile_, font, font_y_offset,
313 GetColor(ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT), 322 GetColor(ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT),
314 background_color); 323 background_color);
315 AddChildView(keyword_hint_view_); 324 AddChildView(keyword_hint_view_);
316 325
317 mic_search_view_ = new MicSearchView(this); 326 mic_search_view_ = new views::ImageButton(this);
327 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON);
328 mic_search_view_->set_accessibility_focusable(true);
329 mic_search_view_->SetTooltipText(
330 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH));
331 mic_search_view_->SetImage(
332 views::Button::STATE_NORMAL,
333 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
334 IDR_OMNIBOX_MIC_SEARCH));
335 mic_search_view_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
336 views::ImageButton::ALIGN_MIDDLE);
318 mic_search_view_->SetVisible(false); 337 mic_search_view_->SetVisible(false);
338 InitTouchableLocationBarView(mic_search_view_);
319 AddChildView(mic_search_view_); 339 AddChildView(mic_search_view_);
320 340
321 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 341 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
322 ContentSettingImageView* content_blocked_view = 342 ContentSettingImageView* content_blocked_view =
323 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, 343 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this,
324 bubble_font, bubble_font_y_offset, 344 bubble_font, bubble_font_y_offset,
325 text_color, background_color); 345 text_color, background_color);
326 content_setting_views_.push_back(content_blocked_view); 346 content_setting_views_.push_back(content_blocked_view);
327 content_blocked_view->SetVisible(false); 347 content_blocked_view->SetVisible(false);
328 AddChildView(content_blocked_view); 348 AddChildView(content_blocked_view);
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 } else if (model_->GetSecurityLevel(false) == ToolbarModel::EV_SECURE) { 729 } else if (model_->GetSecurityLevel(false) == ToolbarModel::EV_SECURE) {
710 ev_bubble_view_->SetLabel(model_->GetEVCertName()); 730 ev_bubble_view_->SetLabel(model_->GetEVCertName());
711 // The largest fraction of the omnibox that can be taken by the EV bubble. 731 // The largest fraction of the omnibox that can be taken by the EV bubble.
712 const double kMaxBubbleFraction = 0.5; 732 const double kMaxBubbleFraction = 0.5;
713 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, 733 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false,
714 kMaxBubbleFraction, kBubblePadding, 734 kMaxBubbleFraction, kBubblePadding,
715 item_padding, 0, ev_bubble_view_); 735 item_padding, 0, ev_bubble_view_);
716 } else { 736 } else {
717 leading_decorations.AddDecoration( 737 leading_decorations.AddDecoration(
718 vertical_edge_thickness(), location_height, 738 vertical_edge_thickness(), location_height,
719 location_icon_view_->GetBuiltInHorizontalPadding(), 739 GetBuiltInHorizontalPaddingForChildViews(),
720 location_icon_view_); 740 location_icon_view_);
721 } 741 }
722 742
723 if (star_view_ && star_view_->visible()) { 743 if (star_view_ && star_view_->visible()) {
724 trailing_decorations.AddDecoration( 744 trailing_decorations.AddDecoration(
725 vertical_edge_thickness(), location_height, 745 vertical_edge_thickness(), location_height,
726 star_view_->GetBuiltInHorizontalPadding(), star_view_); 746 GetBuiltInHorizontalPaddingForChildViews(), star_view_);
727 } 747 }
728 if (script_bubble_icon_view_ && script_bubble_icon_view_->visible()) { 748 if (script_bubble_icon_view_ && script_bubble_icon_view_->visible()) {
729 trailing_decorations.AddDecoration( 749 trailing_decorations.AddDecoration(
730 vertical_edge_thickness(), location_height, 750 vertical_edge_thickness(), location_height,
731 script_bubble_icon_view_->GetBuiltInHorizontalPadding(), 751 GetBuiltInHorizontalPaddingForChildViews(),
732 script_bubble_icon_view_); 752 script_bubble_icon_view_);
733 } 753 }
734 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) { 754 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) {
735 trailing_decorations.AddDecoration( 755 trailing_decorations.AddDecoration(
736 vertical_edge_thickness(), location_height, 756 vertical_edge_thickness(), location_height,
737 open_pdf_in_reader_view_->GetBuiltInHorizontalPadding(), 757 GetBuiltInHorizontalPaddingForChildViews(),
738 open_pdf_in_reader_view_); 758 open_pdf_in_reader_view_);
739 } 759 }
740 for (PageActionViews::const_iterator i(page_action_views_.begin()); 760 for (PageActionViews::const_iterator i(page_action_views_.begin());
741 i != page_action_views_.end(); ++i) { 761 i != page_action_views_.end(); ++i) {
742 if ((*i)->visible()) { 762 if ((*i)->visible()) {
743 trailing_decorations.AddDecoration( 763 trailing_decorations.AddDecoration(
744 vertical_edge_thickness(), location_height, 764 vertical_edge_thickness(), location_height,
745 (*i)->GetBuiltInHorizontalPadding(), (*i)); 765 GetBuiltInHorizontalPaddingForChildViews(), (*i));
746 } 766 }
747 } 767 }
748 if (zoom_view_->visible()) { 768 if (zoom_view_->visible()) {
749 trailing_decorations.AddDecoration(vertical_edge_thickness(), 769 trailing_decorations.AddDecoration(vertical_edge_thickness(),
750 location_height, 0, zoom_view_); 770 location_height, 0, zoom_view_);
751 } 771 }
752 for (ContentSettingViews::const_reverse_iterator i( 772 for (ContentSettingViews::const_reverse_iterator i(
753 content_setting_views_.rbegin()); i != content_setting_views_.rend(); 773 content_setting_views_.rbegin()); i != content_setting_views_.rend();
754 ++i) { 774 ++i) {
755 if ((*i)->visible()) { 775 if ((*i)->visible()) {
756 trailing_decorations.AddDecoration( 776 trailing_decorations.AddDecoration(
757 bubble_location_y, bubble_height, false, 0, item_padding, 777 bubble_location_y, bubble_height, false, 0, item_padding,
758 item_padding, (*i)->GetBuiltInHorizontalPadding(), (*i)); 778 item_padding, GetBuiltInHorizontalPaddingForChildViews(), (*i));
759 } 779 }
760 } 780 }
761 if (autofill_credit_card_view_->visible()) { 781 if (autofill_credit_card_view_->visible()) {
762 trailing_decorations.AddDecoration(vertical_edge_thickness(), 782 trailing_decorations.AddDecoration(vertical_edge_thickness(),
763 location_height, 0, 783 location_height, 0,
764 autofill_credit_card_view_); 784 autofill_credit_card_view_);
765 } 785 }
766 if (mic_search_view_->visible()) { 786 if (mic_search_view_->visible()) {
767 trailing_decorations.AddDecoration(vertical_edge_thickness(), 787 trailing_decorations.AddDecoration(vertical_edge_thickness(),
768 location_height, 0, mic_search_view_); 788 location_height, 0, mic_search_view_);
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 } 1095 }
1076 1096
1077 WebContents* LocationBarView::GetWebContents() const { 1097 WebContents* LocationBarView::GetWebContents() const {
1078 return delegate_->GetWebContents(); 1098 return delegate_->GetWebContents();
1079 } 1099 }
1080 1100
1081 gfx::Rect LocationBarView::GetOmniboxBounds() const { 1101 gfx::Rect LocationBarView::GetOmniboxBounds() const {
1082 return bounds(); 1102 return bounds();
1083 } 1103 }
1084 1104
1105 // static
1106 int LocationBarView::GetBuiltInHorizontalPaddingForChildViews() {
1107 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? GetItemPadding() / 2
Peter Kasting 2013/08/09 20:57:28 Nit: Break after '?', not before ':'.
tfarina 2013/08/10 02:13:40 this is clang-format not me.
Peter Kasting 2013/08/10 07:27:21 I don't care. clang-format is wrong. Do not form
tfarina 2013/08/10 19:11:31 Done.
1108 : 0;
1109 }
1110
1085 int LocationBarView::GetHorizontalEdgeThickness() const { 1111 int LocationBarView::GetHorizontalEdgeThickness() const {
1086 // In maximized popup mode, there isn't any edge. 1112 // In maximized popup mode, there isn't any edge.
1087 return (is_popup_mode_ && browser_ && browser_->window() && 1113 return (is_popup_mode_ && browser_ && browser_->window() &&
1088 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); 1114 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness();
1089 } 1115 }
1090 1116
1091 void LocationBarView::RefreshContentSettingViews() { 1117 void LocationBarView::RefreshContentSettingViews() {
1092 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 1118 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
1093 i != content_setting_views_.end(); ++i) { 1119 i != content_setting_views_.end(); ++i) {
1094 (*i)->Update(model_->GetInputInProgress() ? NULL : GetWebContents()); 1120 (*i)->Update(model_->GetInputInProgress() ? NULL : GetWebContents());
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 const ToolbarModel::SecurityLevel security_level = 1256 const ToolbarModel::SecurityLevel security_level =
1231 model_->GetSecurityLevel(false); 1257 model_->GetSecurityLevel(false);
1232 const SkColor text_color = GetColor(security_level, TEXT); 1258 const SkColor text_color = GetColor(security_level, TEXT);
1233 const SkColor background_color = GetColor(security_level, BACKGROUND); 1259 const SkColor background_color = GetColor(security_level, BACKGROUND);
1234 1260
1235 for (PageActionViews::const_iterator 1261 for (PageActionViews::const_iterator
1236 page_action_view = page_action_views_.begin(); 1262 page_action_view = page_action_views_.begin();
1237 page_action_view != page_action_views_.end(); 1263 page_action_view != page_action_views_.end();
1238 ++page_action_view) { 1264 ++page_action_view) {
1239 gfx::Rect bounds = (*page_action_view)->bounds(); 1265 gfx::Rect bounds = (*page_action_view)->bounds();
1240 int horizontal_padding = GetItemPadding() - 1266 int horizontal_padding =
1241 (*page_action_view)->GetBuiltInHorizontalPadding(); 1267 GetItemPadding() - GetBuiltInHorizontalPaddingForChildViews();
1242 // Make the bounding rectangle include the whole vertical range of the 1268 // Make the bounding rectangle include the whole vertical range of the
1243 // location bar, and the mid-point pixels between adjacent page actions. 1269 // location bar, and the mid-point pixels between adjacent page actions.
1244 // 1270 //
1245 // For odd horizontal_paddings, "horizontal_padding + 1" includes the 1271 // For odd horizontal_paddings, "horizontal_padding + 1" includes the
1246 // mid-point between two page actions in the bounding rectangle. For even 1272 // mid-point between two page actions in the bounding rectangle. For even
1247 // paddings, the +1 is dropped, which is right since there is no pixel at 1273 // paddings, the +1 is dropped, which is right since there is no pixel at
1248 // the mid-point. 1274 // the mid-point.
1249 bounds.Inset(-(horizontal_padding + 1) / 2, 0); 1275 bounds.Inset(-(horizontal_padding + 1) / 2, 0);
1250 location_bar_util::PaintExtensionActionBackground( 1276 location_bar_util::PaintExtensionActionBackground(
1251 *(*page_action_view)->image_view()->page_action(), 1277 *(*page_action_view)->image_view()->page_action(),
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 int LocationBarView::GetInternalHeight(bool use_preferred_size) { 1532 int LocationBarView::GetInternalHeight(bool use_preferred_size) {
1507 int total_height = 1533 int total_height =
1508 use_preferred_size ? GetPreferredSize().height() : height(); 1534 use_preferred_size ? GetPreferredSize().height() : height();
1509 return std::max(total_height - (vertical_edge_thickness() * 2), 0); 1535 return std::max(total_height - (vertical_edge_thickness() * 2), 0);
1510 } 1536 }
1511 1537
1512 bool LocationBarView::HasValidSuggestText() const { 1538 bool LocationBarView::HasValidSuggestText() const {
1513 return suggested_text_view_->visible() && 1539 return suggested_text_view_->visible() &&
1514 !suggested_text_view_->size().IsEmpty(); 1540 !suggested_text_view_->size().IsEmpty();
1515 } 1541 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698