OLD | NEW |
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 Loading... |
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) |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 237 |
234 LocationBarView::~LocationBarView() { | 238 LocationBarView::~LocationBarView() { |
235 if (template_url_service_) | 239 if (template_url_service_) |
236 template_url_service_->RemoveObserver(this); | 240 template_url_service_->RemoveObserver(this); |
237 | 241 |
238 if (search_model_) | 242 if (search_model_) |
239 search_model_->RemoveObserver(this); | 243 search_model_->RemoveObserver(this); |
240 } | 244 } |
241 | 245 |
242 void LocationBarView::Init() { | 246 void LocationBarView::Init() { |
| 247 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're |
| 248 // not prepared for that. |
| 249 DCHECK(GetWidget()); |
| 250 |
243 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 251 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
244 if (mode_ == POPUP) { | 252 if (mode_ == POPUP) { |
245 font_ = rb.GetFont(ui::ResourceBundle::BaseFont); | 253 font_ = rb.GetFont(ui::ResourceBundle::BaseFont); |
246 } else { | 254 } else { |
247 // Use a larger version of the system font. | 255 // Use a larger version of the system font. |
248 font_ = rb.GetFont(ui::ResourceBundle::MediumFont); | 256 font_ = rb.GetFont(ui::ResourceBundle::MediumFont); |
249 } | 257 } |
250 | 258 |
251 // If this makes the font too big, try to make it smaller so it will fit. | 259 // If this makes the font too big, try to make it smaller so it will fit. |
252 const int height = GetInternalHeight(true); | 260 const int height = GetInternalHeight(true); |
253 while ((font_.GetHeight() > height) && (font_.GetFontSize() > 1)) | 261 while ((font_.GetHeight() > height) && (font_.GetFontSize() > 1)) |
254 font_ = font_.DeriveFont(-1); | 262 font_ = font_.DeriveFont(-1); |
255 | 263 |
256 location_icon_view_ = new LocationIconView(this); | 264 location_icon_view_ = new LocationIconView(this); |
257 AddChildView(location_icon_view_); | 265 AddChildView(location_icon_view_); |
258 location_icon_view_->SetVisible(true); | 266 location_icon_view_->SetVisible(true); |
259 location_icon_view_->set_drag_controller(this); | 267 location_icon_view_->set_drag_controller(this); |
260 | 268 |
261 ev_bubble_view_ = | 269 ev_bubble_view_ = |
262 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, | 270 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, |
263 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this); | 271 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), |
| 272 this); |
264 AddChildView(ev_bubble_view_); | 273 AddChildView(ev_bubble_view_); |
265 ev_bubble_view_->SetVisible(false); | 274 ev_bubble_view_->SetVisible(false); |
266 ev_bubble_view_->set_drag_controller(this); | 275 ev_bubble_view_->set_drag_controller(this); |
267 | 276 |
268 // URL edit field. | 277 // URL edit field. |
269 // View container for URL edit field. | 278 // View container for URL edit field. |
270 location_entry_.reset(CreateOmniboxView(this, model_, profile_, | 279 location_entry_.reset(CreateOmniboxView(this, model_, profile_, |
271 command_updater_, mode_ == POPUP, this)); | 280 command_updater_, mode_ == POPUP, this)); |
272 SetLocationEntryFocusable(true); | 281 SetLocationEntryFocusable(true); |
273 | 282 |
274 location_entry_view_ = location_entry_->AddToView(this); | 283 location_entry_view_ = location_entry_->AddToView(this); |
275 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE); | 284 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE); |
276 | 285 |
277 selected_keyword_view_ = new SelectedKeywordView( | 286 selected_keyword_view_ = new SelectedKeywordView( |
278 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, | 287 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, |
279 GetColor(ToolbarModel::NONE, TEXT), | 288 GetColor(ToolbarModel::NONE, TEXT), |
280 profile_); | 289 profile_); |
281 AddChildView(selected_keyword_view_); | 290 AddChildView(selected_keyword_view_); |
282 selected_keyword_view_->SetFont(font_); | 291 selected_keyword_view_->SetFont(font_); |
283 selected_keyword_view_->SetVisible(false); | 292 selected_keyword_view_->SetVisible(false); |
284 | 293 |
285 keyword_hint_view_ = new KeywordHintView(profile_); | 294 keyword_hint_view_ = new KeywordHintView(profile_, this); |
286 AddChildView(keyword_hint_view_); | 295 AddChildView(keyword_hint_view_); |
287 keyword_hint_view_->SetVisible(false); | 296 keyword_hint_view_->SetVisible(false); |
288 keyword_hint_view_->SetFont(font_); | 297 keyword_hint_view_->SetFont(font_); |
289 | 298 |
290 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 299 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
291 ContentSettingImageView* content_blocked_view = | 300 ContentSettingImageView* content_blocked_view = |
292 new ContentSettingImageView(static_cast<ContentSettingsType>(i), | 301 new ContentSettingImageView(static_cast<ContentSettingsType>(i), |
293 kCSBubbleBackgroundImages, this, | 302 kCSBubbleBackgroundImages, this, |
294 font_, | 303 font_, |
295 GetColor(ToolbarModel::NONE, TEXT)); | 304 GetColor(ToolbarModel::NONE, TEXT)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // visible when the location entry has just been initialized. | 344 // visible when the location entry has just been initialized. |
336 Update(NULL); | 345 Update(NULL); |
337 | 346 |
338 OnChanged(); | 347 OnChanged(); |
339 } | 348 } |
340 | 349 |
341 bool LocationBarView::IsInitialized() const { | 350 bool LocationBarView::IsInitialized() const { |
342 return location_entry_view_ != NULL; | 351 return location_entry_view_ != NULL; |
343 } | 352 } |
344 | 353 |
345 // static | |
346 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, | 354 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, |
347 ColorKind kind) { | 355 ColorKind kind) const { |
| 356 #if defined(OS_WIN) |
| 357 if (GetNativeTheme() == ui::NativeThemeWin::instance()) { |
| 358 switch (kind) { |
| 359 case BACKGROUND: |
| 360 return color_utils::GetSysSkColor(COLOR_WINDOW); |
| 361 case TEXT: |
| 362 return color_utils::GetSysSkColor(COLOR_WINDOWTEXT); |
| 363 case SELECTED_TEXT: |
| 364 return color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); |
| 365 default: |
| 366 // Other cases are handled below. |
| 367 break; |
| 368 } |
| 369 } |
| 370 #endif |
348 switch (kind) { | 371 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. | 372 // TODO(beng): source from theme provider. |
355 case BACKGROUND: return kOmniboxBackgroundColor; | 373 case BACKGROUND: return kOmniboxBackgroundColor; |
356 case TEXT: return SK_ColorBLACK; | 374 case TEXT: return SK_ColorBLACK; |
357 case SELECTED_TEXT: return SK_ColorWHITE; | 375 case SELECTED_TEXT: return SK_ColorWHITE; |
358 #endif | |
359 | 376 |
360 case DEEMPHASIZED_TEXT: | 377 case DEEMPHASIZED_TEXT: |
361 return color_utils::AlphaBlend( | 378 return color_utils::AlphaBlend( |
362 GetColor(security_level, TEXT), | 379 GetColor(security_level, TEXT), |
363 GetColor(security_level, BACKGROUND), | 380 GetColor(security_level, BACKGROUND), |
364 128); | 381 128); |
365 | 382 |
366 case SECURITY_TEXT: { | 383 case SECURITY_TEXT: { |
367 SkColor color; | 384 SkColor color; |
368 switch (security_level) { | 385 switch (security_level) { |
369 case ToolbarModel::EV_SECURE: | 386 case ToolbarModel::EV_SECURE: |
370 case ToolbarModel::SECURE: | 387 case ToolbarModel::SECURE: |
371 color = SkColorSetRGB(7, 149, 0); | 388 color = SkColorSetRGB(7, 149, 0); |
372 break; | 389 break; |
373 | 390 |
374 case ToolbarModel::SECURITY_WARNING: | 391 case ToolbarModel::SECURITY_WARNING: |
375 return GetColor(security_level, DEEMPHASIZED_TEXT); | 392 return GetColor(security_level, DEEMPHASIZED_TEXT); |
376 break; | 393 break; |
377 | 394 |
378 case ToolbarModel::SECURITY_ERROR: | 395 case ToolbarModel::SECURITY_ERROR: |
379 color = SkColorSetRGB(162, 0, 0); | 396 color = SkColorSetRGB(162, 0, 0); |
380 break; | 397 break; |
381 | 398 |
382 default: | 399 default: |
383 NOTREACHED(); | 400 NOTREACHED(); |
384 return GetColor(security_level, TEXT); | 401 return GetColor(security_level, TEXT); |
385 } | 402 } |
386 return color_utils::GetReadableColor(color, GetColor(security_level, | 403 return color_utils::GetReadableColor( |
387 BACKGROUND)); | 404 color, GetColor(security_level, BACKGROUND)); |
388 } | 405 } |
389 | 406 |
390 default: | 407 default: |
391 NOTREACHED(); | 408 NOTREACHED(); |
392 return GetColor(security_level, TEXT); | 409 return GetColor(security_level, TEXT); |
393 } | 410 } |
394 } | 411 } |
395 | 412 |
396 // static | 413 // static |
397 int LocationBarView::GetItemPadding() { | 414 int LocationBarView::GetItemPadding() { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 return origin; | 622 return origin; |
606 } | 623 } |
607 | 624 |
608 void LocationBarView::SetInstantSuggestion(const string16& text) { | 625 void LocationBarView::SetInstantSuggestion(const string16& text) { |
609 // Don't show the suggested text if inline autocomplete is prevented. | 626 // Don't show the suggested text if inline autocomplete is prevented. |
610 if (!text.empty()) { | 627 if (!text.empty()) { |
611 if (!suggested_text_view_) { | 628 if (!suggested_text_view_) { |
612 suggested_text_view_ = new views::Label(); | 629 suggested_text_view_ = new views::Label(); |
613 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 630 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
614 suggested_text_view_->SetAutoColorReadabilityEnabled(false); | 631 suggested_text_view_->SetAutoColorReadabilityEnabled(false); |
615 suggested_text_view_->SetEnabledColor(LocationBarView::GetColor( | 632 suggested_text_view_->SetEnabledColor(GetColor( |
616 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); | 633 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); |
617 suggested_text_view_->SetText(text); | 634 suggested_text_view_->SetText(text); |
618 suggested_text_view_->SetFont(location_entry_->GetFont()); | 635 suggested_text_view_->SetFont(location_entry_->GetFont()); |
619 AddChildView(suggested_text_view_); | 636 AddChildView(suggested_text_view_); |
620 } else if (suggested_text_view_->text() != text) { | 637 } else if (suggested_text_view_->text() != text) { |
621 suggested_text_view_->SetText(text); | 638 suggested_text_view_->SetText(text); |
622 } | 639 } |
623 } else if (suggested_text_view_) { | 640 } else if (suggested_text_view_) { |
624 delete suggested_text_view_; | 641 delete suggested_text_view_; |
625 suggested_text_view_ = NULL; | 642 suggested_text_view_ = NULL; |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 } | 1605 } |
1589 | 1606 |
1590 void LocationBarView::CleanupFadeAnimation() { | 1607 void LocationBarView::CleanupFadeAnimation() { |
1591 // Since we're no longer animating we don't need our layer. | 1608 // Since we're no longer animating we don't need our layer. |
1592 SetPaintToLayer(false); | 1609 SetPaintToLayer(false); |
1593 // Bubble labels don't need a transparent background anymore. | 1610 // Bubble labels don't need a transparent background anymore. |
1594 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1611 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
1595 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1612 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
1596 } | 1613 } |
1597 #endif // USE_AURA | 1614 #endif // USE_AURA |
OLD | NEW |