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

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

Issue 11360144: Converts some of the omnibox related classes to support multiple (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 #include "ui/gfx/canvas.h" 71 #include "ui/gfx/canvas.h"
72 #include "ui/gfx/color_utils.h" 72 #include "ui/gfx/color_utils.h"
73 #include "ui/gfx/image/image.h" 73 #include "ui/gfx/image/image.h"
74 #include "ui/gfx/image/image_skia_operations.h" 74 #include "ui/gfx/image/image_skia_operations.h"
75 #include "ui/gfx/skia_util.h" 75 #include "ui/gfx/skia_util.h"
76 #include "ui/views/border.h" 76 #include "ui/views/border.h"
77 #include "ui/views/button_drag_utils.h" 77 #include "ui/views/button_drag_utils.h"
78 #include "ui/views/controls/label.h" 78 #include "ui/views/controls/label.h"
79 #include "ui/views/widget/widget.h" 79 #include "ui/views/widget/widget.h"
80 80
81 #if defined(OS_WIN)
82 #include "ui/base/native_theme/native_theme_win.h"
83 #endif
84
81 #if defined(OS_WIN) && !defined(USE_AURA) 85 #if defined(OS_WIN) && !defined(USE_AURA)
82 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" 86 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h"
83 #endif 87 #endif
84 88
85 #if !defined(OS_CHROMEOS) 89 #if !defined(OS_CHROMEOS)
86 #include "chrome/browser/ui/views/first_run_bubble.h" 90 #include "chrome/browser/ui/views/first_run_bubble.h"
87 #include "ui/base/native_theme/native_theme.h" 91 #include "ui/base/native_theme/native_theme.h"
88 #endif 92 #endif
89 93
90 #if defined(USE_AURA) 94 #if defined(USE_AURA)
95 #include "ui/base/native_theme/native_theme_aura.h"
91 #include "ui/compositor/layer.h" 96 #include "ui/compositor/layer.h"
92 #include "ui/compositor/scoped_layer_animation_settings.h" 97 #include "ui/compositor/scoped_layer_animation_settings.h"
93 #endif 98 #endif
94 99
95 using content::WebContents; 100 using content::WebContents;
96 using views::View; 101 using views::View;
97 102
98 namespace { 103 namespace {
99 104
100 WebContents* GetWebContentsFromDelegate(LocationBarView::Delegate* delegate) { 105 WebContents* GetWebContentsFromDelegate(LocationBarView::Delegate* delegate) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 238
234 LocationBarView::~LocationBarView() { 239 LocationBarView::~LocationBarView() {
235 if (template_url_service_) 240 if (template_url_service_)
236 template_url_service_->RemoveObserver(this); 241 template_url_service_->RemoveObserver(this);
237 242
238 if (search_model_) 243 if (search_model_)
239 search_model_->RemoveObserver(this); 244 search_model_->RemoveObserver(this);
240 } 245 }
241 246
242 void LocationBarView::Init() { 247 void LocationBarView::Init() {
248 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're
249 // not prepared for that.
250 DCHECK(GetWidget());
251
243 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 252 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
244 if (mode_ == POPUP) { 253 if (mode_ == POPUP) {
245 font_ = rb.GetFont(ui::ResourceBundle::BaseFont); 254 font_ = rb.GetFont(ui::ResourceBundle::BaseFont);
246 } else { 255 } else {
247 // Use a larger version of the system font. 256 // Use a larger version of the system font.
248 font_ = rb.GetFont(ui::ResourceBundle::MediumFont); 257 font_ = rb.GetFont(ui::ResourceBundle::MediumFont);
249 } 258 }
250 259
251 // If this makes the font too big, try to make it smaller so it will fit. 260 // If this makes the font too big, try to make it smaller so it will fit.
252 const int height = GetInternalHeight(true); 261 const int height = GetInternalHeight(true);
253 while ((font_.GetHeight() > height) && (font_.GetFontSize() > 1)) 262 while ((font_.GetHeight() > height) && (font_.GetFontSize() > 1))
254 font_ = font_.DeriveFont(-1); 263 font_ = font_.DeriveFont(-1);
255 264
256 location_icon_view_ = new LocationIconView(this); 265 location_icon_view_ = new LocationIconView(this);
257 AddChildView(location_icon_view_); 266 AddChildView(location_icon_view_);
258 location_icon_view_->SetVisible(true); 267 location_icon_view_->SetVisible(true);
259 location_icon_view_->set_drag_controller(this); 268 location_icon_view_->set_drag_controller(this);
260 269
270 const ui::NativeTheme* theme = GetNativeTheme();
271
261 ev_bubble_view_ = 272 ev_bubble_view_ =
262 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, 273 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID,
263 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this); 274 GetColor(theme, ToolbarModel::EV_SECURE, SECURITY_TEXT),
275 this);
264 AddChildView(ev_bubble_view_); 276 AddChildView(ev_bubble_view_);
265 ev_bubble_view_->SetVisible(false); 277 ev_bubble_view_->SetVisible(false);
266 ev_bubble_view_->set_drag_controller(this); 278 ev_bubble_view_->set_drag_controller(this);
267 279
268 // URL edit field. 280 // URL edit field.
269 // View container for URL edit field. 281 // View container for URL edit field.
270 location_entry_.reset(CreateOmniboxView(this, model_, profile_, 282 location_entry_.reset(CreateOmniboxView(this, model_, profile_,
271 command_updater_, mode_ == POPUP, this)); 283 command_updater_, mode_ == POPUP, this));
272 SetLocationEntryFocusable(true); 284 SetLocationEntryFocusable(true);
273 285
274 location_entry_view_ = location_entry_->AddToView(this); 286 location_entry_view_ = location_entry_->AddToView(this);
275 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE); 287 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE);
276 288
277 selected_keyword_view_ = new SelectedKeywordView( 289 selected_keyword_view_ = new SelectedKeywordView(
278 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, 290 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER,
279 GetColor(ToolbarModel::NONE, TEXT), 291 GetColor(theme, ToolbarModel::NONE, TEXT),
280 profile_); 292 profile_);
281 AddChildView(selected_keyword_view_); 293 AddChildView(selected_keyword_view_);
282 selected_keyword_view_->SetFont(font_); 294 selected_keyword_view_->SetFont(font_);
283 selected_keyword_view_->SetVisible(false); 295 selected_keyword_view_->SetVisible(false);
284 296
285 keyword_hint_view_ = new KeywordHintView(profile_); 297 keyword_hint_view_ = new KeywordHintView(profile_);
286 AddChildView(keyword_hint_view_); 298 AddChildView(keyword_hint_view_);
287 keyword_hint_view_->SetVisible(false); 299 keyword_hint_view_->SetVisible(false);
288 keyword_hint_view_->SetFont(font_); 300 keyword_hint_view_->SetFont(font_);
289 301
290 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 302 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
291 ContentSettingImageView* content_blocked_view = 303 ContentSettingImageView* content_blocked_view =
292 new ContentSettingImageView(static_cast<ContentSettingsType>(i), 304 new ContentSettingImageView(static_cast<ContentSettingsType>(i),
293 kCSBubbleBackgroundImages, this, 305 kCSBubbleBackgroundImages, this,
294 font_, 306 font_,
295 GetColor(ToolbarModel::NONE, TEXT)); 307 GetColor(theme, ToolbarModel::NONE, TEXT));
296 content_setting_views_.push_back(content_blocked_view); 308 content_setting_views_.push_back(content_blocked_view);
297 AddChildView(content_blocked_view); 309 AddChildView(content_blocked_view);
298 content_blocked_view->SetVisible(false); 310 content_blocked_view->SetVisible(false);
299 } 311 }
300 312
301 zoom_view_ = new ZoomView(model_, delegate_); 313 zoom_view_ = new ZoomView(model_, delegate_);
302 zoom_view_->set_id(VIEW_ID_ZOOM_BUTTON); 314 zoom_view_->set_id(VIEW_ID_ZOOM_BUTTON);
303 AddChildView(zoom_view_); 315 AddChildView(zoom_view_);
304 316
305 web_intents_button_view_ = 317 web_intents_button_view_ =
306 new WebIntentsButtonView(this, kWIBubbleBackgroundImages, font_, 318 new WebIntentsButtonView(this, kWIBubbleBackgroundImages, font_,
307 GetColor(ToolbarModel::NONE, TEXT)); 319 GetColor(theme, ToolbarModel::NONE, TEXT));
308 AddChildView(web_intents_button_view_); 320 AddChildView(web_intents_button_view_);
309 321
310 open_pdf_in_reader_view_ = new OpenPDFInReaderView(this); 322 open_pdf_in_reader_view_ = new OpenPDFInReaderView(this);
311 AddChildView(open_pdf_in_reader_view_); 323 AddChildView(open_pdf_in_reader_view_);
312 324
313 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { 325 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) {
314 // Note: condition above means that the star icon is hidden in popups and in 326 // Note: condition above means that the star icon is hidden in popups and in
315 // the app launcher. 327 // the app launcher.
316 star_view_ = new StarView(command_updater_); 328 star_view_ = new StarView(command_updater_);
317 AddChildView(star_view_); 329 AddChildView(star_view_);
(...skipping 18 matching lines...) Expand all
336 Update(NULL); 348 Update(NULL);
337 349
338 OnChanged(); 350 OnChanged();
339 } 351 }
340 352
341 bool LocationBarView::IsInitialized() const { 353 bool LocationBarView::IsInitialized() const {
342 return location_entry_view_ != NULL; 354 return location_entry_view_ != NULL;
343 } 355 }
344 356
345 // static 357 // static
346 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, 358 SkColor LocationBarView::GetColor(const ui::NativeTheme* theme,
359 ToolbarModel::SecurityLevel security_level,
347 ColorKind kind) { 360 ColorKind kind) {
361 #if defined(OS_WIN)
362 if (theme == ui::NativeThemeWin::instance()) {
363 switch (kind) {
364 case BACKGROUND:
365 return color_utils::GetSysSkColor(COLOR_WINDOW);
366 case TEXT:
367 return color_utils::GetSysSkColor(COLOR_WINDOWTEXT);
368 case SELECTED_TEXT:
369 return color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT);
370 default:
371 // Other cases are handled below.
372 break;
373 }
374 }
375 #endif
348 switch (kind) { 376 switch (kind) {
349 #if defined(OS_WIN)
350 case BACKGROUND: return color_utils::GetSysSkColor(COLOR_WINDOW);
351 case TEXT: return color_utils::GetSysSkColor(COLOR_WINDOWTEXT);
352 case SELECTED_TEXT: return color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT);
353 #else
354 // TODO(beng): source from theme provider. 377 // TODO(beng): source from theme provider.
355 case BACKGROUND: return kOmniboxBackgroundColor; 378 case BACKGROUND: return kOmniboxBackgroundColor;
356 case TEXT: return SK_ColorBLACK; 379 case TEXT: return SK_ColorBLACK;
357 case SELECTED_TEXT: return SK_ColorWHITE; 380 case SELECTED_TEXT: return SK_ColorWHITE;
358 #endif
359 381
360 case DEEMPHASIZED_TEXT: 382 case DEEMPHASIZED_TEXT:
361 return color_utils::AlphaBlend( 383 return color_utils::AlphaBlend(
362 GetColor(security_level, TEXT), 384 GetColor(theme, security_level, TEXT),
363 GetColor(security_level, BACKGROUND), 385 GetColor(theme, security_level, BACKGROUND),
364 128); 386 128);
365 387
366 case SECURITY_TEXT: { 388 case SECURITY_TEXT: {
367 SkColor color; 389 SkColor color;
368 switch (security_level) { 390 switch (security_level) {
369 case ToolbarModel::EV_SECURE: 391 case ToolbarModel::EV_SECURE:
370 case ToolbarModel::SECURE: 392 case ToolbarModel::SECURE:
371 color = SkColorSetRGB(7, 149, 0); 393 color = SkColorSetRGB(7, 149, 0);
372 break; 394 break;
373 395
374 case ToolbarModel::SECURITY_WARNING: 396 case ToolbarModel::SECURITY_WARNING:
375 return GetColor(security_level, DEEMPHASIZED_TEXT); 397 return GetColor(theme, security_level, DEEMPHASIZED_TEXT);
376 break; 398 break;
377 399
378 case ToolbarModel::SECURITY_ERROR: 400 case ToolbarModel::SECURITY_ERROR:
379 color = SkColorSetRGB(162, 0, 0); 401 color = SkColorSetRGB(162, 0, 0);
380 break; 402 break;
381 403
382 default: 404 default:
383 NOTREACHED(); 405 NOTREACHED();
384 return GetColor(security_level, TEXT); 406 return GetColor(theme, security_level, TEXT);
385 } 407 }
386 return color_utils::GetReadableColor(color, GetColor(security_level, 408 return color_utils::GetReadableColor(color, GetColor(theme,
Peter Kasting 2012/11/08 18:55:47 Nit: Or return color_utils::GetReadableColo
409 security_level,
387 BACKGROUND)); 410 BACKGROUND));
388 } 411 }
389 412
390 default: 413 default:
391 NOTREACHED(); 414 NOTREACHED();
392 return GetColor(security_level, TEXT); 415 return GetColor(theme, security_level, TEXT);
393 } 416 }
394 } 417 }
395 418
396 // static 419 // static
397 int LocationBarView::GetItemPadding() { 420 int LocationBarView::GetItemPadding() {
398 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) 421 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH)
399 return kTouchItemPadding; 422 return kTouchItemPadding;
400 return extensions::FeatureSwitch::script_badges()->IsEnabled() ? 423 return extensions::FeatureSwitch::script_badges()->IsEnabled() ?
401 kDesktopScriptBadgeItemPadding : kDesktopItemPadding; 424 kDesktopScriptBadgeItemPadding : kDesktopItemPadding;
402 } 425 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 } 629 }
607 630
608 void LocationBarView::SetInstantSuggestion(const string16& text) { 631 void LocationBarView::SetInstantSuggestion(const string16& text) {
609 // Don't show the suggested text if inline autocomplete is prevented. 632 // Don't show the suggested text if inline autocomplete is prevented.
610 if (!text.empty()) { 633 if (!text.empty()) {
611 if (!suggested_text_view_) { 634 if (!suggested_text_view_) {
612 suggested_text_view_ = new views::Label(); 635 suggested_text_view_ = new views::Label();
613 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 636 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
614 suggested_text_view_->SetAutoColorReadabilityEnabled(false); 637 suggested_text_view_->SetAutoColorReadabilityEnabled(false);
615 suggested_text_view_->SetEnabledColor(LocationBarView::GetColor( 638 suggested_text_view_->SetEnabledColor(LocationBarView::GetColor(
616 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); 639 GetNativeTheme(), ToolbarModel::NONE,
640 LocationBarView::DEEMPHASIZED_TEXT));
617 suggested_text_view_->SetText(text); 641 suggested_text_view_->SetText(text);
618 suggested_text_view_->SetFont(location_entry_->GetFont()); 642 suggested_text_view_->SetFont(location_entry_->GetFont());
619 AddChildView(suggested_text_view_); 643 AddChildView(suggested_text_view_);
620 } else if (suggested_text_view_->text() != text) { 644 } else if (suggested_text_view_->text() != text) {
621 suggested_text_view_->SetText(text); 645 suggested_text_view_->SetText(text);
622 } 646 }
623 } else if (suggested_text_view_) { 647 } else if (suggested_text_view_) {
624 delete suggested_text_view_; 648 delete suggested_text_view_;
625 suggested_text_view_ = NULL; 649 suggested_text_view_ = NULL;
626 } else { 650 } else {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 987
964 // Draw the background color so that the graphical elements at the edges 988 // Draw the background color so that the graphical elements at the edges
965 // appear over the correct color. (The edit draws its own background, so this 989 // appear over the correct color. (The edit draws its own background, so this
966 // isn't important for that.) 990 // isn't important for that.)
967 // TODO(pkasting): We need images that are transparent in the middle, so we 991 // TODO(pkasting): We need images that are transparent in the middle, so we
968 // can draw the border images over the background color instead of the 992 // can draw the border images over the background color instead of the
969 // reverse; this antialiases better (see comments in 993 // reverse; this antialiases better (see comments in
970 // OmniboxPopupContentsView::OnPaint()). 994 // OmniboxPopupContentsView::OnPaint()).
971 gfx::Rect bounds(GetContentsBounds()); 995 gfx::Rect bounds(GetContentsBounds());
972 bounds.Inset(0, kVerticalEdgeThickness); 996 bounds.Inset(0, kVerticalEdgeThickness);
973 SkColor color(GetColor(ToolbarModel::NONE, BACKGROUND)); 997 SkColor color(GetColor(GetNativeTheme(), ToolbarModel::NONE, BACKGROUND));
974 if (mode_ == NORMAL) { 998 if (mode_ == NORMAL) {
975 SkPaint paint; 999 SkPaint paint;
976 paint.setStyle(SkPaint::kFill_Style); 1000 paint.setStyle(SkPaint::kFill_Style);
977 paint.setAntiAlias(true); 1001 paint.setAntiAlias(true);
978 // TODO(jamescook): Make the corners of the dropdown match the corners of 1002 // TODO(jamescook): Make the corners of the dropdown match the corners of
979 // the omnibox. 1003 // the omnibox.
980 bounds.Inset(kNormalHorizontalEdgeThickness, 0); 1004 bounds.Inset(kNormalHorizontalEdgeThickness, 0);
981 // Paint the actual background color. 1005 // Paint the actual background color.
982 paint.setColor(color); 1006 paint.setColor(color);
983 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); 1007 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 } 1289 }
1266 1290
1267 void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) { 1291 void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) {
1268 TabContents* tab_contents = GetTabContents(); 1292 TabContents* tab_contents = GetTabContents();
1269 // tab_contents may be NULL while the browser is shutting down. 1293 // tab_contents may be NULL while the browser is shutting down.
1270 if (tab_contents == NULL) 1294 if (tab_contents == NULL)
1271 return; 1295 return;
1272 1296
1273 const int32 tab_id = SessionID::IdForTab(tab_contents->web_contents()); 1297 const int32 tab_id = SessionID::IdForTab(tab_contents->web_contents());
1274 const ToolbarModel::SecurityLevel security_level = model_->GetSecurityLevel(); 1298 const ToolbarModel::SecurityLevel security_level = model_->GetSecurityLevel();
1275 const SkColor text_color = GetColor(security_level, TEXT); 1299 const ui::NativeTheme* theme = GetNativeTheme();
1276 const SkColor background_color = GetColor(security_level, BACKGROUND); 1300 const SkColor text_color = GetColor(theme, security_level, TEXT);
1301 const SkColor background_color = GetColor(theme, security_level, BACKGROUND);
1277 1302
1278 for (PageActionViews::const_iterator 1303 for (PageActionViews::const_iterator
1279 page_action_view = page_action_views_.begin(); 1304 page_action_view = page_action_views_.begin();
1280 page_action_view != page_action_views_.end(); 1305 page_action_view != page_action_views_.end();
1281 ++page_action_view) { 1306 ++page_action_view) {
1282 gfx::Rect bounds = (*page_action_view)->bounds(); 1307 gfx::Rect bounds = (*page_action_view)->bounds();
1283 int horizontal_padding = GetItemPadding() - 1308 int horizontal_padding = GetItemPadding() -
1284 (*page_action_view)->GetBuiltInHorizontalPadding(); 1309 (*page_action_view)->GetBuiltInHorizontalPadding();
1285 // Make the bounding rectangle include the whole vertical range of the 1310 // Make the bounding rectangle include the whole vertical range of the
1286 // location bar, and the mid-point pixels between adjacent page actions. 1311 // location bar, and the mid-point pixels between adjacent page actions.
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 } 1613 }
1589 1614
1590 void LocationBarView::CleanupFadeAnimation() { 1615 void LocationBarView::CleanupFadeAnimation() {
1591 // Since we're no longer animating we don't need our layer. 1616 // Since we're no longer animating we don't need our layer.
1592 SetPaintToLayer(false); 1617 SetPaintToLayer(false);
1593 // Bubble labels don't need a transparent background anymore. 1618 // Bubble labels don't need a transparent background anymore.
1594 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1619 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1595 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1620 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1596 } 1621 }
1597 #endif // USE_AURA 1622 #endif // USE_AURA
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698