| 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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 40 #include "chrome/browser/ui/view_ids.h" | 40 #include "chrome/browser/ui/view_ids.h" |
| 41 #include "chrome/browser/ui/views/browser_dialogs.h" | 41 #include "chrome/browser/ui/views/browser_dialogs.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/generated_credit_card_view.h" | 44 #include "chrome/browser/ui/views/location_bar/generated_credit_card_view.h" |
| 45 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 45 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 46 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" | 46 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" |
| 47 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 47 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 48 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" | 48 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" |
| 49 #include "chrome/browser/ui/views/location_bar/origin_chip_view.h" | |
| 50 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 49 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 51 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 50 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
| 52 #include "chrome/browser/ui/views/location_bar/search_button.h" | |
| 53 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 51 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
| 54 #include "chrome/browser/ui/views/location_bar/star_view.h" | 52 #include "chrome/browser/ui/views/location_bar/star_view.h" |
| 55 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" | 53 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" |
| 56 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | 54 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
| 57 #include "chrome/browser/ui/views/location_bar/zoom_view.h" | 55 #include "chrome/browser/ui/views/location_bar/zoom_view.h" |
| 58 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" | 56 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
| 59 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" | 57 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" |
| 60 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" | 58 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" |
| 61 #include "chrome/common/pref_names.h" | 59 #include "chrome/common/pref_names.h" |
| 62 #include "chrome/grit/generated_resources.h" | 60 #include "chrome/grit/generated_resources.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 93 |
| 96 #if !defined(OS_CHROMEOS) | 94 #if !defined(OS_CHROMEOS) |
| 97 #include "chrome/browser/ui/views/first_run_bubble.h" | 95 #include "chrome/browser/ui/views/first_run_bubble.h" |
| 98 #endif | 96 #endif |
| 99 | 97 |
| 100 using content::WebContents; | 98 using content::WebContents; |
| 101 using views::View; | 99 using views::View; |
| 102 | 100 |
| 103 namespace { | 101 namespace { |
| 104 | 102 |
| 105 const gfx::Tween::Type kShowTweenType = gfx::Tween::LINEAR_OUT_SLOW_IN; | |
| 106 const gfx::Tween::Type kHideTweenType = gfx::Tween::FAST_OUT_LINEAR_IN; | |
| 107 | |
| 108 // The search button images are made to look as if they overlay the normal edge | |
| 109 // images, but to align things, the search button needs to be inset horizontally | |
| 110 // by 1 px. | |
| 111 const int kSearchButtonInset = 1; | |
| 112 | |
| 113 int GetEditLeadingInternalSpace() { | 103 int GetEditLeadingInternalSpace() { |
| 114 // The textfield has 1 px of whitespace before the text in the RTL case only. | 104 // The textfield has 1 px of whitespace before the text in the RTL case only. |
| 115 return base::i18n::IsRTL() ? 1 : 0; | 105 return base::i18n::IsRTL() ? 1 : 0; |
| 116 } | 106 } |
| 117 | 107 |
| 118 // Functor for moving BookmarkManagerPrivate page actions to the right via | 108 // Functor for moving BookmarkManagerPrivate page actions to the right via |
| 119 // stable_partition. | 109 // stable_partition. |
| 120 class IsPageActionViewRightAligned { | 110 class IsPageActionViewRightAligned { |
| 121 public: | 111 public: |
| 122 explicit IsPageActionViewRightAligned( | 112 explicit IsPageActionViewRightAligned( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 153 LocationBarView::LocationBarView(Browser* browser, | 143 LocationBarView::LocationBarView(Browser* browser, |
| 154 Profile* profile, | 144 Profile* profile, |
| 155 CommandUpdater* command_updater, | 145 CommandUpdater* command_updater, |
| 156 Delegate* delegate, | 146 Delegate* delegate, |
| 157 bool is_popup_mode) | 147 bool is_popup_mode) |
| 158 : LocationBar(profile), | 148 : LocationBar(profile), |
| 159 OmniboxEditController(command_updater), | 149 OmniboxEditController(command_updater), |
| 160 browser_(browser), | 150 browser_(browser), |
| 161 omnibox_view_(NULL), | 151 omnibox_view_(NULL), |
| 162 delegate_(delegate), | 152 delegate_(delegate), |
| 163 origin_chip_view_(NULL), | |
| 164 location_icon_view_(NULL), | 153 location_icon_view_(NULL), |
| 165 ev_bubble_view_(NULL), | 154 ev_bubble_view_(NULL), |
| 166 ime_inline_autocomplete_view_(NULL), | 155 ime_inline_autocomplete_view_(NULL), |
| 167 selected_keyword_view_(NULL), | 156 selected_keyword_view_(NULL), |
| 168 suggested_text_view_(NULL), | 157 suggested_text_view_(NULL), |
| 169 keyword_hint_view_(NULL), | 158 keyword_hint_view_(NULL), |
| 170 mic_search_view_(NULL), | 159 mic_search_view_(NULL), |
| 171 zoom_view_(NULL), | 160 zoom_view_(NULL), |
| 172 generated_credit_card_view_(NULL), | 161 generated_credit_card_view_(NULL), |
| 173 open_pdf_in_reader_view_(NULL), | 162 open_pdf_in_reader_view_(NULL), |
| 174 manage_passwords_icon_view_(NULL), | 163 manage_passwords_icon_view_(NULL), |
| 175 translate_icon_view_(NULL), | 164 translate_icon_view_(NULL), |
| 176 star_view_(NULL), | 165 star_view_(NULL), |
| 177 search_button_(NULL), | |
| 178 is_popup_mode_(is_popup_mode), | 166 is_popup_mode_(is_popup_mode), |
| 179 show_focus_rect_(false), | 167 show_focus_rect_(false), |
| 180 template_url_service_(NULL), | 168 template_url_service_(NULL), |
| 181 dropdown_animation_offset_(0), | 169 dropdown_animation_offset_(0), |
| 182 starting_omnibox_offset_(0), | |
| 183 current_omnibox_offset_(0), | |
| 184 starting_omnibox_leading_inset_(0), | |
| 185 current_omnibox_leading_inset_(0), | |
| 186 current_omnibox_width_(0), | |
| 187 ending_omnibox_width_(0), | |
| 188 web_contents_null_at_last_refresh_(true) { | 170 web_contents_null_at_last_refresh_(true) { |
| 189 edit_bookmarks_enabled_.Init( | 171 edit_bookmarks_enabled_.Init( |
| 190 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), | 172 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), |
| 191 base::Bind(&LocationBarView::Update, base::Unretained(this), | 173 base::Bind(&LocationBarView::Update, base::Unretained(this), |
| 192 static_cast<content::WebContents*>(NULL))); | 174 static_cast<content::WebContents*>(NULL))); |
| 193 | 175 |
| 194 if (browser_) | 176 if (browser_) |
| 195 browser_->search_model()->AddObserver(this); | 177 browser_->search_model()->AddObserver(this); |
| 196 } | 178 } |
| 197 | 179 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 246 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
| 265 ime_inline_autocomplete_view_->set_background( | 247 ime_inline_autocomplete_view_->set_background( |
| 266 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 248 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
| 267 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 249 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
| 268 ime_inline_autocomplete_view_->SetEnabledColor( | 250 ime_inline_autocomplete_view_->SetEnabledColor( |
| 269 GetNativeTheme()->GetSystemColor( | 251 GetNativeTheme()->GetSystemColor( |
| 270 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 252 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
| 271 ime_inline_autocomplete_view_->SetVisible(false); | 253 ime_inline_autocomplete_view_->SetVisible(false); |
| 272 AddChildView(ime_inline_autocomplete_view_); | 254 AddChildView(ime_inline_autocomplete_view_); |
| 273 | 255 |
| 274 origin_chip_view_ = new OriginChipView(this, profile(), font_list); | |
| 275 origin_chip_view_->SetFocusable(false); | |
| 276 origin_chip_view_->set_drag_controller(this); | |
| 277 AddChildView(origin_chip_view_); | |
| 278 | |
| 279 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); | 256 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); |
| 280 selected_keyword_view_ = new SelectedKeywordView( | 257 selected_keyword_view_ = new SelectedKeywordView( |
| 281 bubble_font_list, text_color, background_color, profile()); | 258 bubble_font_list, text_color, background_color, profile()); |
| 282 AddChildView(selected_keyword_view_); | 259 AddChildView(selected_keyword_view_); |
| 283 | 260 |
| 284 suggested_text_view_ = new views::Label(base::string16(), font_list); | 261 suggested_text_view_ = new views::Label(base::string16(), font_list); |
| 285 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 262 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 286 suggested_text_view_->SetAutoColorReadabilityEnabled(false); | 263 suggested_text_view_->SetAutoColorReadabilityEnabled(false); |
| 287 suggested_text_view_->SetEnabledColor(GetColor( | 264 suggested_text_view_->SetEnabledColor(GetColor( |
| 288 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); | 265 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 AddChildView(manage_passwords_icon_view_); | 309 AddChildView(manage_passwords_icon_view_); |
| 333 | 310 |
| 334 translate_icon_view_ = new TranslateIconView(command_updater()); | 311 translate_icon_view_ = new TranslateIconView(command_updater()); |
| 335 translate_icon_view_->SetVisible(false); | 312 translate_icon_view_->SetVisible(false); |
| 336 AddChildView(translate_icon_view_); | 313 AddChildView(translate_icon_view_); |
| 337 | 314 |
| 338 star_view_ = new StarView(command_updater(), browser_); | 315 star_view_ = new StarView(command_updater(), browser_); |
| 339 star_view_->SetVisible(false); | 316 star_view_->SetVisible(false); |
| 340 AddChildView(star_view_); | 317 AddChildView(star_view_); |
| 341 | 318 |
| 342 search_button_ = new SearchButton(this); | |
| 343 search_button_->SetVisible(false); | |
| 344 AddChildView(search_button_); | |
| 345 | |
| 346 show_url_animation_.reset(new gfx::SlideAnimation(this)); | |
| 347 show_url_animation_->SetTweenType(kShowTweenType); | |
| 348 show_url_animation_->SetSlideDuration(200); | |
| 349 | |
| 350 hide_url_animation_.reset(new gfx::SlideAnimation(this)); | |
| 351 hide_url_animation_->SetTweenType(kHideTweenType); | |
| 352 hide_url_animation_->SetSlideDuration(175); | |
| 353 | |
| 354 // Initialize the location entry. We do this to avoid a black flash which is | 319 // Initialize the location entry. We do this to avoid a black flash which is |
| 355 // visible when the location entry has just been initialized. | 320 // visible when the location entry has just been initialized. |
| 356 Update(NULL); | 321 Update(NULL); |
| 357 } | 322 } |
| 358 | 323 |
| 359 bool LocationBarView::IsInitialized() const { | 324 bool LocationBarView::IsInitialized() const { |
| 360 return omnibox_view_ != NULL; | 325 return omnibox_view_ != NULL; |
| 361 } | 326 } |
| 362 | 327 |
| 363 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, | 328 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 if (star_view_) | 426 if (star_view_) |
| 462 star_view_->SetToggled(on); | 427 star_view_->SetToggled(on); |
| 463 } | 428 } |
| 464 | 429 |
| 465 void LocationBarView::SetTranslateIconToggled(bool on) { | 430 void LocationBarView::SetTranslateIconToggled(bool on) { |
| 466 translate_icon_view_->SetToggled(on); | 431 translate_icon_view_->SetToggled(on); |
| 467 } | 432 } |
| 468 | 433 |
| 469 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { | 434 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { |
| 470 gfx::Point origin(omnibox_view_->bounds().origin()); | 435 gfx::Point origin(omnibox_view_->bounds().origin()); |
| 471 origin.set_x(GetMirroredXInView(origin.x() - current_omnibox_offset_)); | 436 origin.set_x(GetMirroredXInView(origin.x())); |
| 472 views::View::ConvertPointToScreen(this, &origin); | 437 views::View::ConvertPointToScreen(this, &origin); |
| 473 return origin; | 438 return origin; |
| 474 } | 439 } |
| 475 | 440 |
| 476 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { | 441 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { |
| 477 ime_inline_autocomplete_view_->SetText(text); | 442 ime_inline_autocomplete_view_->SetText(text); |
| 478 ime_inline_autocomplete_view_->SetVisible(!text.empty()); | 443 ime_inline_autocomplete_view_->SetVisible(!text.empty()); |
| 479 } | 444 } |
| 480 | 445 |
| 481 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { | 446 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 534 |
| 570 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { | 535 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { |
| 571 state->role = ui::AX_ROLE_GROUP; | 536 state->role = ui::AX_ROLE_GROUP; |
| 572 } | 537 } |
| 573 | 538 |
| 574 gfx::Size LocationBarView::GetPreferredSize() const { | 539 gfx::Size LocationBarView::GetPreferredSize() const { |
| 575 // Compute minimum height. | 540 // Compute minimum height. |
| 576 gfx::Size min_size(border_painter_->GetMinimumSize()); | 541 gfx::Size min_size(border_painter_->GetMinimumSize()); |
| 577 if (!IsInitialized()) | 542 if (!IsInitialized()) |
| 578 return min_size; | 543 return min_size; |
| 579 gfx::Size search_button_min_size(search_button_->GetMinimumSize()); | |
| 580 min_size.SetToMax(search_button_min_size); | |
| 581 | 544 |
| 582 // Compute width of omnibox-leading content. | 545 // Compute width of omnibox-leading content. |
| 583 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); | 546 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
| 584 int leading_width = horizontal_edge_thickness; | 547 int leading_width = horizontal_edge_thickness; |
| 585 // TODO(pkasting): Make the origin chip min width sane, and make the chip | |
| 586 // handle being shrunken down more gracefully; then uncomment this. | |
| 587 /*if (GetToolbarModel()->ShouldShowOriginChip()) | |
| 588 leading_width += origin_chip_view_->GetMinimumSize().width();*/ | |
| 589 if (ShouldShowKeywordBubble()) { | 548 if (ShouldShowKeywordBubble()) { |
| 590 // The selected keyword view can collapse completely. | 549 // The selected keyword view can collapse completely. |
| 591 } else if (ShouldShowEVBubble()) { | 550 } else if (ShouldShowEVBubble()) { |
| 592 leading_width += kBubblePadding + | 551 leading_width += kBubblePadding + |
| 593 ev_bubble_view_->GetMinimumSizeForLabelText( | 552 ev_bubble_view_->GetMinimumSizeForLabelText( |
| 594 GetToolbarModel()->GetEVCertName()).width(); | 553 GetToolbarModel()->GetEVCertName()).width(); |
| 595 } else if (!origin_chip_view_->visible()) { | 554 } else { |
| 596 leading_width += | 555 leading_width += |
| 597 kItemPadding + location_icon_view_->GetMinimumSize().width(); | 556 kItemPadding + location_icon_view_->GetMinimumSize().width(); |
| 598 } | 557 } |
| 599 | 558 |
| 600 // Compute width of omnibox-trailing content. | 559 // Compute width of omnibox-trailing content. |
| 601 int trailing_width = search_button_->visible() ? | 560 int trailing_width = horizontal_edge_thickness; |
| 602 (search_button_->GetMinimumSize().width() + kSearchButtonInset) : | |
| 603 horizontal_edge_thickness; | |
| 604 trailing_width += IncrementalMinimumWidth(star_view_) + | 561 trailing_width += IncrementalMinimumWidth(star_view_) + |
| 605 IncrementalMinimumWidth(translate_icon_view_) + | 562 IncrementalMinimumWidth(translate_icon_view_) + |
| 606 IncrementalMinimumWidth(open_pdf_in_reader_view_) + | 563 IncrementalMinimumWidth(open_pdf_in_reader_view_) + |
| 607 IncrementalMinimumWidth(manage_passwords_icon_view_) + | 564 IncrementalMinimumWidth(manage_passwords_icon_view_) + |
| 608 IncrementalMinimumWidth(zoom_view_) + | 565 IncrementalMinimumWidth(zoom_view_) + |
| 609 IncrementalMinimumWidth(generated_credit_card_view_) + | 566 IncrementalMinimumWidth(generated_credit_card_view_) + |
| 610 IncrementalMinimumWidth(mic_search_view_); | 567 IncrementalMinimumWidth(mic_search_view_); |
| 611 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 568 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 612 i != page_action_views_.end(); ++i) | 569 i != page_action_views_.end(); ++i) |
| 613 trailing_width += IncrementalMinimumWidth((*i)); | 570 trailing_width += IncrementalMinimumWidth((*i)); |
| 614 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 571 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 615 i != content_setting_views_.end(); ++i) | 572 i != content_setting_views_.end(); ++i) |
| 616 trailing_width += IncrementalMinimumWidth((*i)); | 573 trailing_width += IncrementalMinimumWidth((*i)); |
| 617 | 574 |
| 618 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + | 575 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + |
| 619 2 * kItemPadding - omnibox_view_->GetInsets().width() + trailing_width); | 576 2 * kItemPadding - omnibox_view_->GetInsets().width() + trailing_width); |
| 620 return min_size; | 577 return min_size; |
| 621 } | 578 } |
| 622 | 579 |
| 623 void LocationBarView::Layout() { | 580 void LocationBarView::Layout() { |
| 624 if (!IsInitialized()) | 581 if (!IsInitialized()) |
| 625 return; | 582 return; |
| 626 | 583 |
| 627 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip()); | |
| 628 selected_keyword_view_->SetVisible(false); | 584 selected_keyword_view_->SetVisible(false); |
| 629 location_icon_view_->SetVisible(false); | 585 location_icon_view_->SetVisible(false); |
| 630 ev_bubble_view_->SetVisible(false); | 586 ev_bubble_view_->SetVisible(false); |
| 631 keyword_hint_view_->SetVisible(false); | 587 keyword_hint_view_->SetVisible(false); |
| 632 | 588 |
| 633 LocationBarLayout leading_decorations( | 589 LocationBarLayout leading_decorations( |
| 634 LocationBarLayout::LEFT_EDGE, | 590 LocationBarLayout::LEFT_EDGE, |
| 635 kItemPadding - omnibox_view_->GetInsets().left() - | 591 kItemPadding - omnibox_view_->GetInsets().left() - |
| 636 GetEditLeadingInternalSpace()); | 592 GetEditLeadingInternalSpace()); |
| 637 LocationBarLayout trailing_decorations( | 593 LocationBarLayout trailing_decorations( |
| 638 LocationBarLayout::RIGHT_EDGE, | 594 LocationBarLayout::RIGHT_EDGE, |
| 639 kItemPadding - omnibox_view_->GetInsets().right()); | 595 kItemPadding - omnibox_view_->GetInsets().right()); |
| 640 | 596 |
| 641 const int origin_chip_preferred_width = | |
| 642 origin_chip_view_->GetPreferredSize().width(); | |
| 643 const int origin_chip_width = | |
| 644 origin_chip_view_->visible() ? origin_chip_preferred_width : 0; | |
| 645 // Always give the origin chip view its desired size and lay it out, even when | |
| 646 // it's not visible, so we can calculate the correct animation values below | |
| 647 // when switching to tabs that have the origin chip hidden. | |
| 648 origin_chip_view_->SetBounds(0, 0, origin_chip_preferred_width, height()); | |
| 649 origin_chip_view_->Layout(); | |
| 650 | |
| 651 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; | 597 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; |
| 652 const base::string16 keyword(omnibox_view_->model()->keyword()); | 598 const base::string16 keyword(omnibox_view_->model()->keyword()); |
| 653 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 599 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want |
| 654 // to position our child views in this case, because other things may be | 600 // to position our child views in this case, because other things may be |
| 655 // positioned relative to them (e.g. the "bookmark added" bubble if the user | 601 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
| 656 // hits ctrl-d). | 602 // hits ctrl-d). |
| 657 const int location_height = GetInternalHeight(false); | 603 const int location_height = GetInternalHeight(false); |
| 658 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); | 604 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); |
| 659 if (ShouldShowKeywordBubble()) { | 605 if (ShouldShowKeywordBubble()) { |
| 660 leading_decorations.AddDecoration(bubble_location_y, bubble_height, true, 0, | 606 leading_decorations.AddDecoration(bubble_location_y, bubble_height, true, 0, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 677 selected_keyword_view_->set_is_extension_icon(false); | 623 selected_keyword_view_->set_is_extension_icon(false); |
| 678 } | 624 } |
| 679 } | 625 } |
| 680 } else if (ShouldShowEVBubble()) { | 626 } else if (ShouldShowEVBubble()) { |
| 681 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); | 627 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); |
| 682 // The largest fraction of the omnibox that can be taken by the EV bubble. | 628 // The largest fraction of the omnibox that can be taken by the EV bubble. |
| 683 const double kMaxBubbleFraction = 0.5; | 629 const double kMaxBubbleFraction = 0.5; |
| 684 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, | 630 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, |
| 685 kMaxBubbleFraction, kBubblePadding, | 631 kMaxBubbleFraction, kBubblePadding, |
| 686 kItemPadding, ev_bubble_view_); | 632 kItemPadding, ev_bubble_view_); |
| 687 } else if (!origin_chip_view_->visible()) { | 633 } else { |
| 688 leading_decorations.AddDecoration( | 634 leading_decorations.AddDecoration( |
| 689 vertical_edge_thickness(), location_height, | 635 vertical_edge_thickness(), location_height, |
| 690 location_icon_view_); | 636 location_icon_view_); |
| 691 } | 637 } |
| 692 | 638 |
| 693 if (star_view_->visible()) { | 639 if (star_view_->visible()) { |
| 694 trailing_decorations.AddDecoration( | 640 trailing_decorations.AddDecoration( |
| 695 vertical_edge_thickness(), location_height, star_view_); | 641 vertical_edge_thickness(), location_height, star_view_); |
| 696 } | 642 } |
| 697 if (translate_icon_view_->visible()) { | 643 if (translate_icon_view_->visible()) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 !omnibox_view_->IsImeComposing()) { | 688 !omnibox_view_->IsImeComposing()) { |
| 743 trailing_decorations.AddDecoration(vertical_edge_thickness(), | 689 trailing_decorations.AddDecoration(vertical_edge_thickness(), |
| 744 location_height, true, 0, kItemPadding, | 690 location_height, true, 0, kItemPadding, |
| 745 kItemPadding, keyword_hint_view_); | 691 kItemPadding, keyword_hint_view_); |
| 746 if (keyword_hint_view_->keyword() != keyword) | 692 if (keyword_hint_view_->keyword() != keyword) |
| 747 keyword_hint_view_->SetKeyword(keyword); | 693 keyword_hint_view_->SetKeyword(keyword); |
| 748 } | 694 } |
| 749 | 695 |
| 750 // Perform layout. | 696 // Perform layout. |
| 751 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); | 697 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
| 752 int full_width = width() - horizontal_edge_thickness - origin_chip_width; | 698 int full_width = width() - horizontal_edge_thickness; |
| 753 | 699 |
| 754 const gfx::Size search_button_size(search_button_->GetPreferredSize()); | 700 full_width -= horizontal_edge_thickness; |
| 755 const int search_button_reserved_width = | |
| 756 search_button_size.width() + kSearchButtonInset; | |
| 757 full_width -= search_button_->visible() ? | |
| 758 search_button_reserved_width : horizontal_edge_thickness; | |
| 759 int entry_width = full_width; | 701 int entry_width = full_width; |
| 760 leading_decorations.LayoutPass1(&entry_width); | 702 leading_decorations.LayoutPass1(&entry_width); |
| 761 trailing_decorations.LayoutPass1(&entry_width); | 703 trailing_decorations.LayoutPass1(&entry_width); |
| 762 leading_decorations.LayoutPass2(&entry_width); | 704 leading_decorations.LayoutPass2(&entry_width); |
| 763 trailing_decorations.LayoutPass2(&entry_width); | 705 trailing_decorations.LayoutPass2(&entry_width); |
| 764 | 706 |
| 765 int location_needed_width = omnibox_view_->GetTextWidth(); | 707 int location_needed_width = omnibox_view_->GetTextWidth(); |
| 766 int available_width = entry_width - location_needed_width; | 708 int available_width = entry_width - location_needed_width; |
| 767 // The bounds must be wide enough for all the decorations to fit. | 709 // The bounds must be wide enough for all the decorations to fit. |
| 768 gfx::Rect location_bounds( | 710 gfx::Rect location_bounds( |
| 769 origin_chip_width + horizontal_edge_thickness, vertical_edge_thickness(), | 711 horizontal_edge_thickness, vertical_edge_thickness(), |
| 770 std::max(full_width, full_width - entry_width), location_height); | 712 std::max(full_width, full_width - entry_width), location_height); |
| 771 leading_decorations.LayoutPass3(&location_bounds, &available_width); | 713 leading_decorations.LayoutPass3(&location_bounds, &available_width); |
| 772 trailing_decorations.LayoutPass3(&location_bounds, &available_width); | 714 trailing_decorations.LayoutPass3(&location_bounds, &available_width); |
| 773 | 715 |
| 774 // Calculate the animation parameters (see comments on these members in the | |
| 775 // header). We have to do this in Layout, after |origin_chip_view_| is laid | |
| 776 // out, because that may affect the host label offset in the origin chip. | |
| 777 const base::string16& chip_text(origin_chip_view_->host_label_text()); | |
| 778 // If the chip is clicked, the omnibox text will become the toolbar model's | |
| 779 // formatted URL. We can't ask the omnibox for its current text, because | |
| 780 // while the chip is visible the current text is empty. | |
| 781 size_t prefix_end = 0; | |
| 782 const base::string16& omnibox_text( | |
| 783 GetToolbarModel()->GetFormattedURL(&prefix_end)); | |
| 784 // Do a case-insensitive search to better match cases like | |
| 785 // "Settings" <-> "chrome://settings". Skip any pre-hostname text. | |
| 786 size_t chip_text_offset = std::search( | |
| 787 omnibox_text.begin() + prefix_end, omnibox_text.end(), | |
| 788 chip_text.begin(), chip_text.end(), | |
| 789 base::CaseInsensitiveCompare<base::char16>()) - omnibox_text.begin(); | |
| 790 // If we couldn't find the chip text, try checking whether the omnibox text | |
| 791 // starts with it, as is true for e.g. file: URLs. | |
| 792 if ((chip_text_offset >= omnibox_text.length()) && | |
| 793 StartsWith(omnibox_text, chip_text, true)) | |
| 794 chip_text_offset = 0; | |
| 795 const gfx::FontList& font_list = omnibox_view_->GetFontList(); | |
| 796 const int chip_text_width = gfx::GetStringWidth(chip_text, font_list); | |
| 797 const int old_starting_offset = starting_omnibox_offset_; | |
| 798 const int old_starting_leading_inset = starting_omnibox_leading_inset_; | |
| 799 const int old_ending_width = ending_omnibox_width_; | |
| 800 starting_omnibox_offset_ = current_omnibox_offset_ = 0; | |
| 801 starting_omnibox_leading_inset_ = current_omnibox_leading_inset_ = 0; | |
| 802 ending_omnibox_width_ = gfx::GetStringWidth(omnibox_text, font_list); | |
| 803 if (chip_text_offset < omnibox_text.length()) { | |
| 804 if (base::i18n::IsRTL()) | |
| 805 chip_text_offset += chip_text.length(); | |
| 806 base::string16 extra_omnibox_text(base::i18n::IsRTL() ? | |
| 807 omnibox_text.substr(chip_text_offset) : | |
| 808 omnibox_text.substr(0, chip_text_offset)); | |
| 809 starting_omnibox_leading_inset_ = | |
| 810 gfx::GetStringWidth(extra_omnibox_text, font_list); | |
| 811 starting_omnibox_offset_ = origin_chip_view_->HostLabelOffset() - | |
| 812 starting_omnibox_leading_inset_; | |
| 813 current_omnibox_width_ = chip_text_width; | |
| 814 } else { | |
| 815 // If the chip text wasn't found in the omnibox text, then instead of | |
| 816 // starting the show animation clipped to the "hostname", we'll start with | |
| 817 // the entire omnibox text visible, clipped to the remaining chip width, and | |
| 818 // only animate any necessary expansion of that width, without moving the | |
| 819 // omnibox bounds. | |
| 820 current_omnibox_width_ = origin_chip_view_->WidthFromStartOfLabels(); | |
| 821 } | |
| 822 | |
| 823 // End the animations immediately if the parameters have changed. | |
| 824 if ((starting_omnibox_offset_ != old_starting_offset) || | |
| 825 (starting_omnibox_leading_inset_ != old_starting_leading_inset) || | |
| 826 (ending_omnibox_width_ != old_ending_width)) | |
| 827 EndOriginChipAnimations(true); | |
| 828 | |
| 829 // Also end the animations immediately if there's nothing to animate (but do | |
| 830 // allow the chip to fade back in). | |
| 831 const ui::NativeTheme* native_theme = GetNativeTheme(); | |
| 832 const SkColor ending_selection_text_color = native_theme->GetSystemColor( | |
| 833 ui::NativeTheme::kColorId_TextfieldSelectionColor); | |
| 834 const SkColor ending_selection_background_color = | |
| 835 native_theme->GetSystemColor( | |
| 836 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); | |
| 837 if ((starting_omnibox_offset_ == 0) && | |
| 838 (starting_omnibox_leading_inset_ == 0) && | |
| 839 (ending_omnibox_width_ == chip_text_width) && | |
| 840 (hide_url_animation_->is_animating() || | |
| 841 ((ending_selection_text_color == | |
| 842 origin_chip_view_->pressed_text_color()) && | |
| 843 (ending_selection_background_color == | |
| 844 origin_chip_view_->pressed_background_color())))) | |
| 845 EndOriginChipAnimations(false); | |
| 846 | |
| 847 if (show_url_animation_->is_animating()) { | |
| 848 omnibox_view_->SetSelectionTextColor(gfx::Tween::ColorValueBetween( | |
| 849 show_url_animation_->GetCurrentValue(), | |
| 850 origin_chip_view_->pressed_text_color(), | |
| 851 ending_selection_text_color)); | |
| 852 omnibox_view_->SetSelectionBackgroundColor(gfx::Tween::ColorValueBetween( | |
| 853 show_url_animation_->GetCurrentValue(), | |
| 854 origin_chip_view_->pressed_background_color(), | |
| 855 ending_selection_background_color)); | |
| 856 current_omnibox_offset_ = | |
| 857 show_url_animation_->CurrentValueBetween(starting_omnibox_offset_, 0); | |
| 858 current_omnibox_leading_inset_ = show_url_animation_->CurrentValueBetween( | |
| 859 starting_omnibox_leading_inset_, 0); | |
| 860 current_omnibox_width_ = show_url_animation_->CurrentValueBetween( | |
| 861 chip_text_width, ending_omnibox_width_); | |
| 862 } else if (hide_url_animation_->is_animating()) { | |
| 863 current_omnibox_offset_ = | |
| 864 hide_url_animation_->CurrentValueBetween(0, starting_omnibox_offset_); | |
| 865 current_omnibox_leading_inset_ = hide_url_animation_->CurrentValueBetween( | |
| 866 0, starting_omnibox_leading_inset_); | |
| 867 current_omnibox_width_ = hide_url_animation_->CurrentValueBetween( | |
| 868 ending_omnibox_width_, chip_text_width); | |
| 869 } | |
| 870 // Contract |available_width| as necessary, but never expand it. This way, | |
| 871 // we'll never draw suggested text at first and then have it disappear | |
| 872 // midway through the animation. | |
| 873 if (current_omnibox_offset_ > 0) | |
| 874 available_width -= current_omnibox_offset_; | |
| 875 location_bounds.Inset(current_omnibox_offset_, 0, 0, 0); | |
| 876 | |
| 877 // Layout out the suggested text view right aligned to the location | 716 // Layout out the suggested text view right aligned to the location |
| 878 // entry. Only show the suggested text if we can fit the text from one | 717 // entry. Only show the suggested text if we can fit the text from one |
| 879 // character before the end of the selection to the end of the text and the | 718 // character before the end of the selection to the end of the text and the |
| 880 // suggested text. If we can't it means either the suggested text is too big, | 719 // suggested text. If we can't it means either the suggested text is too big, |
| 881 // or the user has scrolled. | 720 // or the user has scrolled. |
| 882 | 721 |
| 883 // TODO(sky): We could potentially adjust this to take into account suggested | 722 // TODO(sky): We could potentially adjust this to take into account suggested |
| 884 // text to force using minimum size if necessary, but currently the chance of | 723 // text to force using minimum size if necessary, but currently the chance of |
| 885 // showing keyword hints and suggested text is minimal and we're not confident | 724 // showing keyword hints and suggested text is minimal and we're not confident |
| 886 // this is the right approach for suggested text. | 725 // this is the right approach for suggested text. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 x = 0; | 784 x = 0; |
| 946 else if (location_needed_width + width > entry_width) | 785 else if (location_needed_width + width > entry_width) |
| 947 x = entry_width - width; | 786 x = entry_width - width; |
| 948 location_bounds.set_width(x); | 787 location_bounds.set_width(x); |
| 949 ime_inline_autocomplete_view_->SetBounds( | 788 ime_inline_autocomplete_view_->SetBounds( |
| 950 location_bounds.right(), location_bounds.y(), | 789 location_bounds.right(), location_bounds.y(), |
| 951 std::min(width, entry_width), location_bounds.height()); | 790 std::min(width, entry_width), location_bounds.height()); |
| 952 } | 791 } |
| 953 | 792 |
| 954 omnibox_view_->SetBoundsRect(location_bounds); | 793 omnibox_view_->SetBoundsRect(location_bounds); |
| 955 | |
| 956 search_button_->SetBoundsRect(gfx::Rect( | |
| 957 gfx::Point(width() - search_button_reserved_width, 0), | |
| 958 search_button_size)); | |
| 959 } | 794 } |
| 960 | 795 |
| 961 //////////////////////////////////////////////////////////////////////////////// | 796 //////////////////////////////////////////////////////////////////////////////// |
| 962 // LocationBarView, public OmniboxEditController implementation: | 797 // LocationBarView, public OmniboxEditController implementation: |
| 963 | 798 |
| 964 void LocationBarView::Update(const WebContents* contents) { | 799 void LocationBarView::Update(const WebContents* contents) { |
| 965 mic_search_view_->SetVisible( | 800 mic_search_view_->SetVisible( |
| 966 !GetToolbarModel()->input_in_progress() && browser_ && | 801 !GetToolbarModel()->input_in_progress() && browser_ && |
| 967 browser_->search_model()->voice_search_supported()); | 802 browser_->search_model()->voice_search_supported()); |
| 968 RefreshContentSettingViews(); | 803 RefreshContentSettingViews(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 984 omnibox_view_->Update(); | 819 omnibox_view_->Update(); |
| 985 | 820 |
| 986 OnChanged(); // NOTE: Calls Layout(). | 821 OnChanged(); // NOTE: Calls Layout(). |
| 987 } | 822 } |
| 988 | 823 |
| 989 void LocationBarView::ResetTabState(WebContents* contents) { | 824 void LocationBarView::ResetTabState(WebContents* contents) { |
| 990 omnibox_view_->ResetTabState(contents); | 825 omnibox_view_->ResetTabState(contents); |
| 991 } | 826 } |
| 992 | 827 |
| 993 void LocationBarView::ShowURL() { | 828 void LocationBarView::ShowURL() { |
| 994 // Start the animation before calling ShowURL(), since the latter eventually | |
| 995 // calls back to Layout(), and if the animation is not marked as "running", | |
| 996 // we'll draw the omnibox in its final position briefly until the first | |
| 997 // animation callback reaches us. | |
| 998 if (chrome::ShouldDisplayOriginChip()) { | |
| 999 // If we're currently hiding, reverse the hide by swapping to the show | |
| 1000 // animation, offset so that the text is in the same position. | |
| 1001 if (hide_url_animation_->is_animating()) { | |
| 1002 const double show_value = GetValueForAnimation(false); | |
| 1003 hide_url_animation_->Reset(); | |
| 1004 show_url_animation_->Show(); | |
| 1005 // This must be done after calling Show() and is not equivalent to | |
| 1006 // calling Reset(n) before Show(); Reset() would have caused the entire | |
| 1007 // animation curve (and time) to run between this value and the final | |
| 1008 // value, whereas Show() + SetCurrentValue() skips the animation forward | |
| 1009 // to the supplied value. | |
| 1010 show_url_animation_->SetCurrentValue(show_value); | |
| 1011 } else { | |
| 1012 show_url_animation_->Show(); | |
| 1013 } | |
| 1014 } | |
| 1015 omnibox_view_->ShowURL(); | 829 omnibox_view_->ShowURL(); |
| 1016 } | 830 } |
| 1017 | 831 |
| 1018 void LocationBarView::EndOriginChipAnimations(bool cancel_fade) { | |
| 1019 show_url_animation_->End(); | |
| 1020 hide_url_animation_->End(); | |
| 1021 if (cancel_fade) | |
| 1022 origin_chip_view_->CancelFade(); | |
| 1023 } | |
| 1024 | |
| 1025 ToolbarModel* LocationBarView::GetToolbarModel() { | 832 ToolbarModel* LocationBarView::GetToolbarModel() { |
| 1026 return delegate_->GetToolbarModel(); | 833 return delegate_->GetToolbarModel(); |
| 1027 } | 834 } |
| 1028 | 835 |
| 1029 WebContents* LocationBarView::GetWebContents() { | 836 WebContents* LocationBarView::GetWebContents() { |
| 1030 return delegate_->GetWebContents(); | 837 return delegate_->GetWebContents(); |
| 1031 } | 838 } |
| 1032 | 839 |
| 1033 //////////////////////////////////////////////////////////////////////////////// | 840 //////////////////////////////////////////////////////////////////////////////// |
| 1034 // LocationBarView, private: | 841 // LocationBarView, private: |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 return suggested_text_view_->visible() && | 1004 return suggested_text_view_->visible() && |
| 1198 !suggested_text_view_->size().IsEmpty(); | 1005 !suggested_text_view_->size().IsEmpty(); |
| 1199 } | 1006 } |
| 1200 | 1007 |
| 1201 bool LocationBarView::ShouldShowKeywordBubble() const { | 1008 bool LocationBarView::ShouldShowKeywordBubble() const { |
| 1202 return !omnibox_view_->model()->keyword().empty() && | 1009 return !omnibox_view_->model()->keyword().empty() && |
| 1203 !omnibox_view_->model()->is_keyword_hint(); | 1010 !omnibox_view_->model()->is_keyword_hint(); |
| 1204 } | 1011 } |
| 1205 | 1012 |
| 1206 bool LocationBarView::ShouldShowEVBubble() const { | 1013 bool LocationBarView::ShouldShowEVBubble() const { |
| 1207 return !chrome::ShouldDisplayOriginChip() && | 1014 return |
| 1208 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); | 1015 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); |
| 1209 } | 1016 } |
| 1210 | 1017 |
| 1211 double LocationBarView::GetValueForAnimation(bool hide) const { | |
| 1212 int calculated_offset; | |
| 1213 const gfx::Tween::Type tween_type = hide ? kHideTweenType : kShowTweenType; | |
| 1214 int start_offset = starting_omnibox_offset_, end_offset = 0; | |
| 1215 if (hide) | |
| 1216 std::swap(start_offset, end_offset); | |
| 1217 const int desired_offset = abs(current_omnibox_offset_); | |
| 1218 // Binary-search the value space (0 <= value <= 1) to find the appropriate | |
| 1219 // position. We only bother to iterate to within 1/64 of the desired value, | |
| 1220 // because the longer of the two animations will only run for twelve frames | |
| 1221 // anyway (200 ms * 60 Hz), so at this point we'll have a maximum error of | |
| 1222 // less than a fifth of an animation frame, which the user isn't going to | |
| 1223 // notice. | |
| 1224 // | |
| 1225 // We have to use this method because Tween::CalculateValue() is not | |
| 1226 // necessarily easily invertible. Luckily, this only runs when the user | |
| 1227 // reverses the animation (rare), and the limit on how many iterations we'll | |
| 1228 // do ensures the cost is unnoticeable. | |
| 1229 double value = 0.5; | |
| 1230 double step = value / 2; | |
| 1231 do { | |
| 1232 calculated_offset = abs(gfx::Tween::IntValueBetween( | |
| 1233 gfx::Tween::CalculateValue(tween_type, value), start_offset, | |
| 1234 end_offset)); | |
| 1235 if (calculated_offset < desired_offset) | |
| 1236 value += step; | |
| 1237 else if (calculated_offset > desired_offset) | |
| 1238 value -= step; | |
| 1239 step /= 2; | |
| 1240 } while ((calculated_offset != desired_offset) && (step >= (1.0 / 64))); | |
| 1241 return value; | |
| 1242 } | |
| 1243 | |
| 1244 void LocationBarView::ResetShowAnimationAndColors() { | |
| 1245 show_url_animation_->Reset(); | |
| 1246 omnibox_view_->UseDefaultSelectionTextColor(); | |
| 1247 omnibox_view_->UseDefaultSelectionBackgroundColor(); | |
| 1248 } | |
| 1249 | |
| 1250 //////////////////////////////////////////////////////////////////////////////// | 1018 //////////////////////////////////////////////////////////////////////////////// |
| 1251 // LocationBarView, private LocationBar implementation: | 1019 // LocationBarView, private LocationBar implementation: |
| 1252 | 1020 |
| 1253 void LocationBarView::ShowFirstRunBubble() { | 1021 void LocationBarView::ShowFirstRunBubble() { |
| 1254 // Wait until search engines have loaded to show the first run bubble. | 1022 // Wait until search engines have loaded to show the first run bubble. |
| 1255 TemplateURLService* url_service = | 1023 TemplateURLService* url_service = |
| 1256 TemplateURLServiceFactory::GetForProfile(profile()); | 1024 TemplateURLServiceFactory::GetForProfile(profile()); |
| 1257 if (!url_service->loaded()) { | 1025 if (!url_service->loaded()) { |
| 1258 template_url_service_ = url_service; | 1026 template_url_service_ = url_service; |
| 1259 template_url_service_->AddObserver(this); | 1027 template_url_service_->AddObserver(this); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 SchedulePaint(); | 1113 SchedulePaint(); |
| 1346 } | 1114 } |
| 1347 | 1115 |
| 1348 void LocationBarView::UpdateGeneratedCreditCardView() { | 1116 void LocationBarView::UpdateGeneratedCreditCardView() { |
| 1349 generated_credit_card_view_->Update(); | 1117 generated_credit_card_view_->Update(); |
| 1350 Layout(); | 1118 Layout(); |
| 1351 SchedulePaint(); | 1119 SchedulePaint(); |
| 1352 } | 1120 } |
| 1353 | 1121 |
| 1354 void LocationBarView::SaveStateToContents(WebContents* contents) { | 1122 void LocationBarView::SaveStateToContents(WebContents* contents) { |
| 1355 // If we're about to switch tabs, complete any current animations, so that if | |
| 1356 // the user is in the midst of hiding the URL, when he returns to this tab, | |
| 1357 // the URL will be hidden rather than shown. | |
| 1358 // NOTE: This must be called before SaveStateToTab(). | |
| 1359 EndOriginChipAnimations(true); | |
| 1360 omnibox_view_->SaveStateToTab(contents); | 1123 omnibox_view_->SaveStateToTab(contents); |
| 1361 } | 1124 } |
| 1362 | 1125 |
| 1363 const OmniboxView* LocationBarView::GetOmniboxView() const { | 1126 const OmniboxView* LocationBarView::GetOmniboxView() const { |
| 1364 return omnibox_view_; | 1127 return omnibox_view_; |
| 1365 } | 1128 } |
| 1366 | 1129 |
| 1367 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { | 1130 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { |
| 1368 return this; | 1131 return this; |
| 1369 } | 1132 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | 1232 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
| 1470 } | 1233 } |
| 1471 | 1234 |
| 1472 // The border itself will be drawn in PaintChildren() since it includes an | 1235 // The border itself will be drawn in PaintChildren() since it includes an |
| 1473 // inner shadow which should be drawn over the contents. | 1236 // inner shadow which should be drawn over the contents. |
| 1474 } | 1237 } |
| 1475 | 1238 |
| 1476 void LocationBarView::PaintChildren(gfx::Canvas* canvas, | 1239 void LocationBarView::PaintChildren(gfx::Canvas* canvas, |
| 1477 const views::CullSet& cull_set) { | 1240 const views::CullSet& cull_set) { |
| 1478 // Paint all the children except for the omnibox itself, which may need to be | 1241 // Paint all the children except for the omnibox itself, which may need to be |
| 1479 // clipped if it's animating in, and the origin chip and the search button, | 1242 // clipped if it's animating in. |
| 1480 // which will be painted after the border. | |
| 1481 for (int i = 0, count = child_count(); i < count; ++i) { | 1243 for (int i = 0, count = child_count(); i < count; ++i) { |
| 1482 views::View* child = child_at(i); | 1244 views::View* child = child_at(i); |
| 1483 if (!child->layer() && (child != omnibox_view_) && | 1245 if (!child->layer() && (child != omnibox_view_)) |
| 1484 (child != origin_chip_view_) && (child != search_button_)) | |
| 1485 child->Paint(canvas, cull_set); | 1246 child->Paint(canvas, cull_set); |
| 1486 } | 1247 } |
| 1487 | 1248 |
| 1488 { | 1249 { |
| 1489 gfx::ScopedCanvas scoped_canvas(canvas); | 1250 gfx::ScopedCanvas scoped_canvas(canvas); |
| 1490 if (show_url_animation_->is_animating() || | |
| 1491 hide_url_animation_->is_animating()) { | |
| 1492 gfx::Rect clip_rect(omnibox_view_->bounds()); | |
| 1493 clip_rect.Inset(current_omnibox_leading_inset_, 0, 0, 0); | |
| 1494 clip_rect.set_width(current_omnibox_width_); | |
| 1495 clip_rect.set_x(GetMirroredXForRect(clip_rect)); | |
| 1496 canvas->ClipRect(clip_rect); | |
| 1497 } | |
| 1498 omnibox_view_->Paint(canvas, cull_set); | 1251 omnibox_view_->Paint(canvas, cull_set); |
| 1499 } | 1252 } |
| 1500 | 1253 |
| 1501 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need | 1254 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need |
| 1502 // the focus rect to appear on top of children we paint here rather than | 1255 // the focus rect to appear on top of children we paint here rather than |
| 1503 // OnPaint(). | 1256 // OnPaint(). |
| 1504 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. | 1257 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. |
| 1505 if (show_focus_rect_ && HasFocus()) | 1258 if (show_focus_rect_ && HasFocus()) |
| 1506 canvas->DrawFocusRect(omnibox_view_->bounds()); | 1259 canvas->DrawFocusRect(omnibox_view_->bounds()); |
| 1507 | 1260 |
| 1508 // Maximized popup windows don't draw the horizontal edges. We implement this | 1261 // Maximized popup windows don't draw the horizontal edges. We implement this |
| 1509 // by simply expanding the paint area outside the view by the edge thickness. | 1262 // by simply expanding the paint area outside the view by the edge thickness. |
| 1510 gfx::Rect border_rect(GetContentsBounds()); | 1263 gfx::Rect border_rect(GetContentsBounds()); |
| 1511 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) | 1264 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) |
| 1512 border_rect.Inset(-kPopupEdgeThickness, 0); | 1265 border_rect.Inset(-kPopupEdgeThickness, 0); |
| 1513 views::Painter::PaintPainterAt(canvas, border_painter_.get(), border_rect); | 1266 views::Painter::PaintPainterAt(canvas, border_painter_.get(), border_rect); |
| 1514 | |
| 1515 // The origin chip and the search button must be painted after the border so | |
| 1516 // that the border shadow is not drawn over them. | |
| 1517 origin_chip_view_->Paint(canvas, cull_set); | |
| 1518 search_button_->Paint(canvas, cull_set); | |
| 1519 } | 1267 } |
| 1520 | 1268 |
| 1521 //////////////////////////////////////////////////////////////////////////////// | 1269 //////////////////////////////////////////////////////////////////////////////// |
| 1522 // LocationBarView, private views::ButtonListener implementation: | 1270 // LocationBarView, private views::ButtonListener implementation: |
| 1523 | 1271 |
| 1524 void LocationBarView::ButtonPressed(views::Button* sender, | 1272 void LocationBarView::ButtonPressed(views::Button* sender, |
| 1525 const ui::Event& event) { | 1273 const ui::Event& event) { |
| 1526 if (sender == mic_search_view_) { | 1274 DCHECK_EQ(mic_search_view_, sender); |
| 1527 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); | 1275 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); |
| 1528 return; | |
| 1529 } | |
| 1530 | |
| 1531 DCHECK_EQ(search_button_, sender); | |
| 1532 // TODO(pkasting): When macourteau adds UMA stats for this, wire them up here. | |
| 1533 omnibox_view_->model()->AcceptInput( | |
| 1534 ui::DispositionFromEventFlags(event.flags()), false); | |
| 1535 } | 1276 } |
| 1536 | 1277 |
| 1537 //////////////////////////////////////////////////////////////////////////////// | 1278 //////////////////////////////////////////////////////////////////////////////// |
| 1538 // LocationBarView, private views::DragController implementation: | 1279 // LocationBarView, private views::DragController implementation: |
| 1539 | 1280 |
| 1540 void LocationBarView::WriteDragDataForView(views::View* sender, | 1281 void LocationBarView::WriteDragDataForView(views::View* sender, |
| 1541 const gfx::Point& press_pt, | 1282 const gfx::Point& press_pt, |
| 1542 OSExchangeData* data) { | 1283 OSExchangeData* data) { |
| 1543 DCHECK_NE(GetDragOperationsForView(sender, press_pt), | 1284 DCHECK_NE(GetDragOperationsForView(sender, press_pt), |
| 1544 ui::DragDropTypes::DRAG_NONE); | 1285 ui::DragDropTypes::DRAG_NONE); |
| 1545 | 1286 |
| 1546 WebContents* web_contents = GetWebContents(); | 1287 WebContents* web_contents = GetWebContents(); |
| 1547 FaviconTabHelper* favicon_tab_helper = | 1288 FaviconTabHelper* favicon_tab_helper = |
| 1548 FaviconTabHelper::FromWebContents(web_contents); | 1289 FaviconTabHelper::FromWebContents(web_contents); |
| 1549 gfx::ImageSkia favicon = favicon_tab_helper->GetFavicon().AsImageSkia(); | 1290 gfx::ImageSkia favicon = favicon_tab_helper->GetFavicon().AsImageSkia(); |
| 1550 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), | 1291 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), |
| 1551 web_contents->GetTitle(), | 1292 web_contents->GetTitle(), |
| 1552 favicon, | 1293 favicon, |
| 1553 NULL, | 1294 NULL, |
| 1554 data, | 1295 data, |
| 1555 sender->GetWidget()); | 1296 sender->GetWidget()); |
| 1556 } | 1297 } |
| 1557 | 1298 |
| 1558 int LocationBarView::GetDragOperationsForView(views::View* sender, | 1299 int LocationBarView::GetDragOperationsForView(views::View* sender, |
| 1559 const gfx::Point& p) { | 1300 const gfx::Point& p) { |
| 1560 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_) || | 1301 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_)); |
| 1561 (sender == origin_chip_view_)); | |
| 1562 WebContents* web_contents = delegate_->GetWebContents(); | 1302 WebContents* web_contents = delegate_->GetWebContents(); |
| 1563 return (web_contents && web_contents->GetURL().is_valid() && | 1303 return (web_contents && web_contents->GetURL().is_valid() && |
| 1564 (!GetOmniboxView()->IsEditingOrEmpty() || | 1304 (!GetOmniboxView()->IsEditingOrEmpty())) ? |
| 1565 sender == origin_chip_view_)) ? | |
| 1566 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) : | 1305 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) : |
| 1567 ui::DragDropTypes::DRAG_NONE; | 1306 ui::DragDropTypes::DRAG_NONE; |
| 1568 } | 1307 } |
| 1569 | 1308 |
| 1570 bool LocationBarView::CanStartDragForView(View* sender, | 1309 bool LocationBarView::CanStartDragForView(View* sender, |
| 1571 const gfx::Point& press_pt, | 1310 const gfx::Point& press_pt, |
| 1572 const gfx::Point& p) { | 1311 const gfx::Point& p) { |
| 1573 return true; | 1312 return true; |
| 1574 } | 1313 } |
| 1575 | 1314 |
| 1576 //////////////////////////////////////////////////////////////////////////////// | 1315 //////////////////////////////////////////////////////////////////////////////// |
| 1577 // LocationBarView, private OmniboxEditController implementation: | 1316 // LocationBarView, private OmniboxEditController implementation: |
| 1578 | 1317 |
| 1579 void LocationBarView::OnChanged() { | 1318 void LocationBarView::OnChanged() { |
| 1580 int icon_id = omnibox_view_->GetIcon(); | 1319 int icon_id = omnibox_view_->GetIcon(); |
| 1581 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon_id)); | 1320 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon_id)); |
| 1582 location_icon_view_->ShowTooltip(!GetOmniboxView()->IsEditingOrEmpty()); | 1321 location_icon_view_->ShowTooltip(!GetOmniboxView()->IsEditingOrEmpty()); |
| 1583 | 1322 |
| 1584 ToolbarModel* toolbar_model = GetToolbarModel(); | |
| 1585 chrome::DisplaySearchButtonConditions conditions = | |
| 1586 chrome::GetDisplaySearchButtonConditions(); | |
| 1587 bool meets_conditions = | |
| 1588 (conditions == chrome::DISPLAY_SEARCH_BUTTON_ALWAYS) || | |
| 1589 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) && | |
| 1590 (toolbar_model->WouldPerformSearchTermReplacement(true) || | |
| 1591 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && | |
| 1592 toolbar_model->input_in_progress()))); | |
| 1593 search_button_->SetVisible(!is_popup_mode_ && meets_conditions); | |
| 1594 search_button_->UpdateIcon(icon_id == IDR_OMNIBOX_SEARCH); | |
| 1595 | |
| 1596 origin_chip_view_->OnChanged(); | |
| 1597 | |
| 1598 Layout(); | 1323 Layout(); |
| 1599 SchedulePaint(); | 1324 SchedulePaint(); |
| 1600 } | 1325 } |
| 1601 | 1326 |
| 1602 void LocationBarView::OnSetFocus() { | 1327 void LocationBarView::OnSetFocus() { |
| 1603 GetFocusManager()->SetFocusedView(this); | 1328 GetFocusManager()->SetFocusedView(this); |
| 1604 } | 1329 } |
| 1605 | 1330 |
| 1606 InstantController* LocationBarView::GetInstant() { | 1331 InstantController* LocationBarView::GetInstant() { |
| 1607 return delegate_->GetInstant(); | 1332 return delegate_->GetInstant(); |
| 1608 } | 1333 } |
| 1609 | 1334 |
| 1610 const ToolbarModel* LocationBarView::GetToolbarModel() const { | 1335 const ToolbarModel* LocationBarView::GetToolbarModel() const { |
| 1611 return delegate_->GetToolbarModel(); | 1336 return delegate_->GetToolbarModel(); |
| 1612 } | 1337 } |
| 1613 | 1338 |
| 1614 void LocationBarView::HideURL() { | |
| 1615 DCHECK(chrome::ShouldDisplayOriginChip()); | |
| 1616 | |
| 1617 // If we're currently showing, reverse the hide by swapping to the hide | |
| 1618 // animation, offset so that the text is in the same position. | |
| 1619 if (show_url_animation_->is_animating()) { | |
| 1620 const double hide_value = GetValueForAnimation(true); | |
| 1621 ResetShowAnimationAndColors(); | |
| 1622 hide_url_animation_->Show(); | |
| 1623 // This must be done after calling Show() and is not equivalent to Reset(n); | |
| 1624 // see comments in ShowURL(). | |
| 1625 hide_url_animation_->SetCurrentValue(hide_value); | |
| 1626 } else { | |
| 1627 hide_url_animation_->Show(); | |
| 1628 } | |
| 1629 } | |
| 1630 | |
| 1631 //////////////////////////////////////////////////////////////////////////////// | 1339 //////////////////////////////////////////////////////////////////////////////// |
| 1632 // LocationBarView, private DropdownBarHostDelegate implementation: | 1340 // LocationBarView, private DropdownBarHostDelegate implementation: |
| 1633 | 1341 |
| 1634 void LocationBarView::SetFocusAndSelection(bool select_all) { | 1342 void LocationBarView::SetFocusAndSelection(bool select_all) { |
| 1635 FocusLocation(select_all); | 1343 FocusLocation(select_all); |
| 1636 } | 1344 } |
| 1637 | 1345 |
| 1638 void LocationBarView::SetAnimationOffset(int offset) { | 1346 void LocationBarView::SetAnimationOffset(int offset) { |
| 1639 dropdown_animation_offset_ = offset; | 1347 dropdown_animation_offset_ = offset; |
| 1640 } | 1348 } |
| 1641 | 1349 |
| 1642 //////////////////////////////////////////////////////////////////////////////// | 1350 //////////////////////////////////////////////////////////////////////////////// |
| 1643 // LocationBarView, private gfx::AnimationDelegate implementation: | |
| 1644 | |
| 1645 void LocationBarView::AnimationProgressed(const gfx::Animation* animation) { | |
| 1646 DCHECK((animation == show_url_animation_.get()) || | |
| 1647 (animation == hide_url_animation_.get())); | |
| 1648 Layout(); | |
| 1649 SchedulePaint(); | |
| 1650 } | |
| 1651 | |
| 1652 void LocationBarView::AnimationEnded(const gfx::Animation* animation) { | |
| 1653 if (animation == show_url_animation_.get()) { | |
| 1654 ResetShowAnimationAndColors(); | |
| 1655 Layout(); | |
| 1656 SchedulePaint(); | |
| 1657 } else { | |
| 1658 DCHECK(animation == hide_url_animation_.get()); | |
| 1659 hide_url_animation_->Reset(); | |
| 1660 origin_chip_view_->FadeIn(); | |
| 1661 omnibox_view_->HideURL(); // Calls OnChanged(), triggering layout. | |
| 1662 } | |
| 1663 } | |
| 1664 | |
| 1665 //////////////////////////////////////////////////////////////////////////////// | |
| 1666 // LocationBarView, private TemplateURLServiceObserver implementation: | 1351 // LocationBarView, private TemplateURLServiceObserver implementation: |
| 1667 | 1352 |
| 1668 void LocationBarView::OnTemplateURLServiceChanged() { | 1353 void LocationBarView::OnTemplateURLServiceChanged() { |
| 1669 template_url_service_->RemoveObserver(this); | 1354 template_url_service_->RemoveObserver(this); |
| 1670 template_url_service_ = NULL; | 1355 template_url_service_ = NULL; |
| 1671 // If the browser is no longer active, let's not show the info bubble, as this | 1356 // If the browser is no longer active, let's not show the info bubble, as this |
| 1672 // would make the browser the active window again. | 1357 // would make the browser the active window again. |
| 1673 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1358 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
| 1674 ShowFirstRunBubble(); | 1359 ShowFirstRunBubble(); |
| 1675 } | 1360 } |
| 1676 | 1361 |
| 1677 //////////////////////////////////////////////////////////////////////////////// | 1362 //////////////////////////////////////////////////////////////////////////////// |
| 1678 // LocationBarView, private SearchModelObserver implementation: | 1363 // LocationBarView, private SearchModelObserver implementation: |
| 1679 | 1364 |
| 1680 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1365 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
| 1681 const SearchModel::State& new_state) { | 1366 const SearchModel::State& new_state) { |
| 1682 const bool visible = !GetToolbarModel()->input_in_progress() && | 1367 const bool visible = !GetToolbarModel()->input_in_progress() && |
| 1683 new_state.voice_search_supported; | 1368 new_state.voice_search_supported; |
| 1684 if (mic_search_view_->visible() != visible) { | 1369 if (mic_search_view_->visible() != visible) { |
| 1685 mic_search_view_->SetVisible(visible); | 1370 mic_search_view_->SetVisible(visible); |
| 1686 Layout(); | 1371 Layout(); |
| 1687 } | 1372 } |
| 1688 } | 1373 } |
| OLD | NEW |