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" | 51 #include "chrome/browser/ui/views/location_bar/search_button.h" |
53 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 52 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
54 #include "chrome/browser/ui/views/location_bar/star_view.h" | 53 #include "chrome/browser/ui/views/location_bar/star_view.h" |
55 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" | 54 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" |
56 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | 55 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
57 #include "chrome/browser/ui/views/location_bar/zoom_view.h" | 56 #include "chrome/browser/ui/views/location_bar/zoom_view.h" |
58 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" | 57 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
59 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" | 58 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 95 |
97 #if !defined(OS_CHROMEOS) | 96 #if !defined(OS_CHROMEOS) |
98 #include "chrome/browser/ui/views/first_run_bubble.h" | 97 #include "chrome/browser/ui/views/first_run_bubble.h" |
99 #endif | 98 #endif |
100 | 99 |
101 using content::WebContents; | 100 using content::WebContents; |
102 using views::View; | 101 using views::View; |
103 | 102 |
104 namespace { | 103 namespace { |
105 | 104 |
106 const gfx::Tween::Type kShowTweenType = gfx::Tween::LINEAR_OUT_SLOW_IN; | |
107 const gfx::Tween::Type kHideTweenType = gfx::Tween::FAST_OUT_LINEAR_IN; | |
108 | |
109 // The search button images are made to look as if they overlay the normal edge | 105 // The search button images are made to look as if they overlay the normal edge |
110 // images, but to align things, the search button needs to be inset horizontally | 106 // images, but to align things, the search button needs to be inset horizontally |
111 // by 1 px. | 107 // by 1 px. |
112 const int kSearchButtonInset = 1; | 108 const int kSearchButtonInset = 1; |
113 | 109 |
114 int GetEditLeadingInternalSpace() { | 110 int GetEditLeadingInternalSpace() { |
115 // The textfield has 1 px of whitespace before the text in the RTL case only. | 111 // The textfield has 1 px of whitespace before the text in the RTL case only. |
116 return base::i18n::IsRTL() ? 1 : 0; | 112 return base::i18n::IsRTL() ? 1 : 0; |
117 } | 113 } |
118 | 114 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 LocationBarView::LocationBarView(Browser* browser, | 150 LocationBarView::LocationBarView(Browser* browser, |
155 Profile* profile, | 151 Profile* profile, |
156 CommandUpdater* command_updater, | 152 CommandUpdater* command_updater, |
157 Delegate* delegate, | 153 Delegate* delegate, |
158 bool is_popup_mode) | 154 bool is_popup_mode) |
159 : LocationBar(profile), | 155 : LocationBar(profile), |
160 OmniboxEditController(command_updater), | 156 OmniboxEditController(command_updater), |
161 browser_(browser), | 157 browser_(browser), |
162 omnibox_view_(NULL), | 158 omnibox_view_(NULL), |
163 delegate_(delegate), | 159 delegate_(delegate), |
164 origin_chip_view_(NULL), | |
165 location_icon_view_(NULL), | 160 location_icon_view_(NULL), |
166 ev_bubble_view_(NULL), | 161 ev_bubble_view_(NULL), |
167 ime_inline_autocomplete_view_(NULL), | 162 ime_inline_autocomplete_view_(NULL), |
168 selected_keyword_view_(NULL), | 163 selected_keyword_view_(NULL), |
169 suggested_text_view_(NULL), | 164 suggested_text_view_(NULL), |
170 keyword_hint_view_(NULL), | 165 keyword_hint_view_(NULL), |
171 mic_search_view_(NULL), | 166 mic_search_view_(NULL), |
172 zoom_view_(NULL), | 167 zoom_view_(NULL), |
173 generated_credit_card_view_(NULL), | 168 generated_credit_card_view_(NULL), |
174 open_pdf_in_reader_view_(NULL), | 169 open_pdf_in_reader_view_(NULL), |
175 manage_passwords_icon_view_(NULL), | 170 manage_passwords_icon_view_(NULL), |
176 translate_icon_view_(NULL), | 171 translate_icon_view_(NULL), |
177 star_view_(NULL), | 172 star_view_(NULL), |
178 search_button_(NULL), | 173 search_button_(NULL), |
179 is_popup_mode_(is_popup_mode), | 174 is_popup_mode_(is_popup_mode), |
180 show_focus_rect_(false), | 175 show_focus_rect_(false), |
181 template_url_service_(NULL), | 176 template_url_service_(NULL), |
182 dropdown_animation_offset_(0), | 177 dropdown_animation_offset_(0), |
183 starting_omnibox_offset_(0), | |
184 current_omnibox_offset_(0), | |
185 starting_omnibox_leading_inset_(0), | |
186 current_omnibox_leading_inset_(0), | |
187 current_omnibox_width_(0), | |
188 ending_omnibox_width_(0), | |
189 web_contents_null_at_last_refresh_(true) { | 178 web_contents_null_at_last_refresh_(true) { |
190 edit_bookmarks_enabled_.Init( | 179 edit_bookmarks_enabled_.Init( |
191 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), | 180 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), |
192 base::Bind(&LocationBarView::Update, base::Unretained(this), | 181 base::Bind(&LocationBarView::Update, base::Unretained(this), |
193 static_cast<content::WebContents*>(NULL))); | 182 static_cast<content::WebContents*>(NULL))); |
194 | 183 |
195 if (browser_) | 184 if (browser_) |
196 browser_->search_model()->AddObserver(this); | 185 browser_->search_model()->AddObserver(this); |
197 | 186 |
198 ui_zoom::ZoomEventManager::GetForBrowserContext(profile) | 187 ui_zoom::ZoomEventManager::GetForBrowserContext(profile) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 260 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
272 ime_inline_autocomplete_view_->set_background( | 261 ime_inline_autocomplete_view_->set_background( |
273 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 262 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
274 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 263 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
275 ime_inline_autocomplete_view_->SetEnabledColor( | 264 ime_inline_autocomplete_view_->SetEnabledColor( |
276 GetNativeTheme()->GetSystemColor( | 265 GetNativeTheme()->GetSystemColor( |
277 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 266 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
278 ime_inline_autocomplete_view_->SetVisible(false); | 267 ime_inline_autocomplete_view_->SetVisible(false); |
279 AddChildView(ime_inline_autocomplete_view_); | 268 AddChildView(ime_inline_autocomplete_view_); |
280 | 269 |
281 origin_chip_view_ = new OriginChipView(this, profile(), font_list); | |
282 origin_chip_view_->SetFocusable(false); | |
283 origin_chip_view_->set_drag_controller(this); | |
284 AddChildView(origin_chip_view_); | |
285 | |
286 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); | 270 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); |
287 selected_keyword_view_ = new SelectedKeywordView( | 271 selected_keyword_view_ = new SelectedKeywordView( |
288 bubble_font_list, text_color, background_color, profile()); | 272 bubble_font_list, text_color, background_color, profile()); |
289 AddChildView(selected_keyword_view_); | 273 AddChildView(selected_keyword_view_); |
290 | 274 |
291 suggested_text_view_ = new views::Label(base::string16(), font_list); | 275 suggested_text_view_ = new views::Label(base::string16(), font_list); |
292 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 276 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
293 suggested_text_view_->SetAutoColorReadabilityEnabled(false); | 277 suggested_text_view_->SetAutoColorReadabilityEnabled(false); |
294 suggested_text_view_->SetEnabledColor(GetColor( | 278 suggested_text_view_->SetEnabledColor(GetColor( |
295 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); | 279 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 AddChildView(translate_icon_view_); | 327 AddChildView(translate_icon_view_); |
344 | 328 |
345 star_view_ = new StarView(command_updater(), browser_); | 329 star_view_ = new StarView(command_updater(), browser_); |
346 star_view_->SetVisible(false); | 330 star_view_->SetVisible(false); |
347 AddChildView(star_view_); | 331 AddChildView(star_view_); |
348 | 332 |
349 search_button_ = new SearchButton(this); | 333 search_button_ = new SearchButton(this); |
350 search_button_->SetVisible(false); | 334 search_button_->SetVisible(false); |
351 AddChildView(search_button_); | 335 AddChildView(search_button_); |
352 | 336 |
353 show_url_animation_.reset(new gfx::SlideAnimation(this)); | |
354 show_url_animation_->SetTweenType(kShowTweenType); | |
355 show_url_animation_->SetSlideDuration(200); | |
356 | |
357 hide_url_animation_.reset(new gfx::SlideAnimation(this)); | |
358 hide_url_animation_->SetTweenType(kHideTweenType); | |
359 hide_url_animation_->SetSlideDuration(175); | |
360 | |
361 // Initialize the location entry. We do this to avoid a black flash which is | 337 // Initialize the location entry. We do this to avoid a black flash which is |
362 // visible when the location entry has just been initialized. | 338 // visible when the location entry has just been initialized. |
363 Update(NULL); | 339 Update(NULL); |
364 } | 340 } |
365 | 341 |
366 bool LocationBarView::IsInitialized() const { | 342 bool LocationBarView::IsInitialized() const { |
367 return omnibox_view_ != NULL; | 343 return omnibox_view_ != NULL; |
368 } | 344 } |
369 | 345 |
370 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, | 346 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 if (star_view_) | 444 if (star_view_) |
469 star_view_->SetToggled(on); | 445 star_view_->SetToggled(on); |
470 } | 446 } |
471 | 447 |
472 void LocationBarView::SetTranslateIconToggled(bool on) { | 448 void LocationBarView::SetTranslateIconToggled(bool on) { |
473 translate_icon_view_->SetToggled(on); | 449 translate_icon_view_->SetToggled(on); |
474 } | 450 } |
475 | 451 |
476 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { | 452 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { |
477 gfx::Point origin(omnibox_view_->bounds().origin()); | 453 gfx::Point origin(omnibox_view_->bounds().origin()); |
478 origin.set_x(GetMirroredXInView(origin.x() - current_omnibox_offset_)); | 454 origin.set_x(GetMirroredXInView(origin.x())); |
479 views::View::ConvertPointToScreen(this, &origin); | 455 views::View::ConvertPointToScreen(this, &origin); |
480 return origin; | 456 return origin; |
481 } | 457 } |
482 | 458 |
483 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { | 459 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { |
484 ime_inline_autocomplete_view_->SetText(text); | 460 ime_inline_autocomplete_view_->SetText(text); |
485 ime_inline_autocomplete_view_->SetVisible(!text.empty()); | 461 ime_inline_autocomplete_view_->SetVisible(!text.empty()); |
486 } | 462 } |
487 | 463 |
488 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { | 464 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 // Compute minimum height. | 558 // Compute minimum height. |
583 gfx::Size min_size(border_painter_->GetMinimumSize()); | 559 gfx::Size min_size(border_painter_->GetMinimumSize()); |
584 if (!IsInitialized()) | 560 if (!IsInitialized()) |
585 return min_size; | 561 return min_size; |
586 gfx::Size search_button_min_size(search_button_->GetMinimumSize()); | 562 gfx::Size search_button_min_size(search_button_->GetMinimumSize()); |
587 min_size.SetToMax(search_button_min_size); | 563 min_size.SetToMax(search_button_min_size); |
588 | 564 |
589 // Compute width of omnibox-leading content. | 565 // Compute width of omnibox-leading content. |
590 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); | 566 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
591 int leading_width = horizontal_edge_thickness; | 567 int leading_width = horizontal_edge_thickness; |
592 // TODO(pkasting): Make the origin chip min width sane, and make the chip | |
593 // handle being shrunken down more gracefully; then uncomment this. | |
594 /*if (GetToolbarModel()->ShouldShowOriginChip()) | |
595 leading_width += origin_chip_view_->GetMinimumSize().width();*/ | |
596 if (ShouldShowKeywordBubble()) { | 568 if (ShouldShowKeywordBubble()) { |
597 // The selected keyword view can collapse completely. | 569 // The selected keyword view can collapse completely. |
598 } else if (ShouldShowEVBubble()) { | 570 } else if (ShouldShowEVBubble()) { |
599 leading_width += kBubblePadding + | 571 leading_width += kBubblePadding + |
600 ev_bubble_view_->GetMinimumSizeForLabelText( | 572 ev_bubble_view_->GetMinimumSizeForLabelText( |
601 GetToolbarModel()->GetEVCertName()).width(); | 573 GetToolbarModel()->GetEVCertName()).width(); |
602 } else if (!origin_chip_view_->visible()) { | 574 } else { |
603 leading_width += | 575 leading_width += |
604 kItemPadding + location_icon_view_->GetMinimumSize().width(); | 576 kItemPadding + location_icon_view_->GetMinimumSize().width(); |
605 } | 577 } |
606 | 578 |
607 // Compute width of omnibox-trailing content. | 579 // Compute width of omnibox-trailing content. |
608 int trailing_width = search_button_->visible() ? | 580 int trailing_width = search_button_->visible() ? |
609 (search_button_->GetMinimumSize().width() + kSearchButtonInset) : | 581 (search_button_->GetMinimumSize().width() + kSearchButtonInset) : |
610 horizontal_edge_thickness; | 582 horizontal_edge_thickness; |
611 trailing_width += IncrementalMinimumWidth(star_view_) + | 583 trailing_width += IncrementalMinimumWidth(star_view_) + |
612 IncrementalMinimumWidth(translate_icon_view_) + | 584 IncrementalMinimumWidth(translate_icon_view_) + |
(...skipping 11 matching lines...) Expand all Loading... |
624 | 596 |
625 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + | 597 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + |
626 2 * kItemPadding - omnibox_view_->GetInsets().width() + trailing_width); | 598 2 * kItemPadding - omnibox_view_->GetInsets().width() + trailing_width); |
627 return min_size; | 599 return min_size; |
628 } | 600 } |
629 | 601 |
630 void LocationBarView::Layout() { | 602 void LocationBarView::Layout() { |
631 if (!IsInitialized()) | 603 if (!IsInitialized()) |
632 return; | 604 return; |
633 | 605 |
634 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip()); | |
635 selected_keyword_view_->SetVisible(false); | 606 selected_keyword_view_->SetVisible(false); |
636 location_icon_view_->SetVisible(false); | 607 location_icon_view_->SetVisible(false); |
637 ev_bubble_view_->SetVisible(false); | 608 ev_bubble_view_->SetVisible(false); |
638 keyword_hint_view_->SetVisible(false); | 609 keyword_hint_view_->SetVisible(false); |
639 | 610 |
640 LocationBarLayout leading_decorations( | 611 LocationBarLayout leading_decorations( |
641 LocationBarLayout::LEFT_EDGE, | 612 LocationBarLayout::LEFT_EDGE, |
642 kItemPadding - omnibox_view_->GetInsets().left() - | 613 kItemPadding - omnibox_view_->GetInsets().left() - |
643 GetEditLeadingInternalSpace()); | 614 GetEditLeadingInternalSpace()); |
644 LocationBarLayout trailing_decorations( | 615 LocationBarLayout trailing_decorations( |
645 LocationBarLayout::RIGHT_EDGE, | 616 LocationBarLayout::RIGHT_EDGE, |
646 kItemPadding - omnibox_view_->GetInsets().right()); | 617 kItemPadding - omnibox_view_->GetInsets().right()); |
647 | 618 |
648 const int origin_chip_preferred_width = | |
649 origin_chip_view_->GetPreferredSize().width(); | |
650 const int origin_chip_width = | |
651 origin_chip_view_->visible() ? origin_chip_preferred_width : 0; | |
652 // Always give the origin chip view its desired size and lay it out, even when | |
653 // it's not visible, so we can calculate the correct animation values below | |
654 // when switching to tabs that have the origin chip hidden. | |
655 origin_chip_view_->SetBounds(0, 0, origin_chip_preferred_width, height()); | |
656 origin_chip_view_->Layout(); | |
657 | |
658 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; | 619 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; |
659 const base::string16 keyword(omnibox_view_->model()->keyword()); | 620 const base::string16 keyword(omnibox_view_->model()->keyword()); |
660 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 621 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want |
661 // to position our child views in this case, because other things may be | 622 // to position our child views in this case, because other things may be |
662 // positioned relative to them (e.g. the "bookmark added" bubble if the user | 623 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
663 // hits ctrl-d). | 624 // hits ctrl-d). |
664 const int location_height = GetInternalHeight(false); | 625 const int location_height = GetInternalHeight(false); |
665 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); | 626 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); |
666 if (ShouldShowKeywordBubble()) { | 627 if (ShouldShowKeywordBubble()) { |
667 leading_decorations.AddDecoration(bubble_location_y, bubble_height, true, 0, | 628 leading_decorations.AddDecoration(bubble_location_y, bubble_height, true, 0, |
(...skipping 16 matching lines...) Expand all Loading... |
684 selected_keyword_view_->set_is_extension_icon(false); | 645 selected_keyword_view_->set_is_extension_icon(false); |
685 } | 646 } |
686 } | 647 } |
687 } else if (ShouldShowEVBubble()) { | 648 } else if (ShouldShowEVBubble()) { |
688 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); | 649 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); |
689 // The largest fraction of the omnibox that can be taken by the EV bubble. | 650 // The largest fraction of the omnibox that can be taken by the EV bubble. |
690 const double kMaxBubbleFraction = 0.5; | 651 const double kMaxBubbleFraction = 0.5; |
691 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, | 652 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, |
692 kMaxBubbleFraction, kBubblePadding, | 653 kMaxBubbleFraction, kBubblePadding, |
693 kItemPadding, ev_bubble_view_); | 654 kItemPadding, ev_bubble_view_); |
694 } else if (!origin_chip_view_->visible()) { | 655 } else { |
695 leading_decorations.AddDecoration( | 656 leading_decorations.AddDecoration( |
696 vertical_edge_thickness(), location_height, | 657 vertical_edge_thickness(), location_height, |
697 location_icon_view_); | 658 location_icon_view_); |
698 } | 659 } |
699 | 660 |
700 if (star_view_->visible()) { | 661 if (star_view_->visible()) { |
701 trailing_decorations.AddDecoration( | 662 trailing_decorations.AddDecoration( |
702 vertical_edge_thickness(), location_height, star_view_); | 663 vertical_edge_thickness(), location_height, star_view_); |
703 } | 664 } |
704 if (translate_icon_view_->visible()) { | 665 if (translate_icon_view_->visible()) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 !omnibox_view_->IsImeComposing()) { | 710 !omnibox_view_->IsImeComposing()) { |
750 trailing_decorations.AddDecoration(vertical_edge_thickness(), | 711 trailing_decorations.AddDecoration(vertical_edge_thickness(), |
751 location_height, true, 0, kItemPadding, | 712 location_height, true, 0, kItemPadding, |
752 kItemPadding, keyword_hint_view_); | 713 kItemPadding, keyword_hint_view_); |
753 if (keyword_hint_view_->keyword() != keyword) | 714 if (keyword_hint_view_->keyword() != keyword) |
754 keyword_hint_view_->SetKeyword(keyword); | 715 keyword_hint_view_->SetKeyword(keyword); |
755 } | 716 } |
756 | 717 |
757 // Perform layout. | 718 // Perform layout. |
758 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); | 719 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
759 int full_width = width() - horizontal_edge_thickness - origin_chip_width; | 720 int full_width = width() - horizontal_edge_thickness; |
760 | 721 |
761 const gfx::Size search_button_size(search_button_->GetPreferredSize()); | 722 const gfx::Size search_button_size(search_button_->GetPreferredSize()); |
762 const int search_button_reserved_width = | 723 const int search_button_reserved_width = |
763 search_button_size.width() + kSearchButtonInset; | 724 search_button_size.width() + kSearchButtonInset; |
764 full_width -= search_button_->visible() ? | 725 full_width -= search_button_->visible() ? |
765 search_button_reserved_width : horizontal_edge_thickness; | 726 search_button_reserved_width : horizontal_edge_thickness; |
766 int entry_width = full_width; | 727 int entry_width = full_width; |
767 leading_decorations.LayoutPass1(&entry_width); | 728 leading_decorations.LayoutPass1(&entry_width); |
768 trailing_decorations.LayoutPass1(&entry_width); | 729 trailing_decorations.LayoutPass1(&entry_width); |
769 leading_decorations.LayoutPass2(&entry_width); | 730 leading_decorations.LayoutPass2(&entry_width); |
770 trailing_decorations.LayoutPass2(&entry_width); | 731 trailing_decorations.LayoutPass2(&entry_width); |
771 | 732 |
772 int location_needed_width = omnibox_view_->GetTextWidth(); | 733 int location_needed_width = omnibox_view_->GetTextWidth(); |
773 int available_width = entry_width - location_needed_width; | 734 int available_width = entry_width - location_needed_width; |
774 // The bounds must be wide enough for all the decorations to fit. | 735 // The bounds must be wide enough for all the decorations to fit. |
775 gfx::Rect location_bounds( | 736 gfx::Rect location_bounds( |
776 origin_chip_width + horizontal_edge_thickness, vertical_edge_thickness(), | 737 horizontal_edge_thickness, vertical_edge_thickness(), |
777 std::max(full_width, full_width - entry_width), location_height); | 738 std::max(full_width, full_width - entry_width), location_height); |
778 leading_decorations.LayoutPass3(&location_bounds, &available_width); | 739 leading_decorations.LayoutPass3(&location_bounds, &available_width); |
779 trailing_decorations.LayoutPass3(&location_bounds, &available_width); | 740 trailing_decorations.LayoutPass3(&location_bounds, &available_width); |
780 | 741 |
781 // Calculate the animation parameters (see comments on these members in the | |
782 // header). We have to do this in Layout, after |origin_chip_view_| is laid | |
783 // out, because that may affect the host label offset in the origin chip. | |
784 const base::string16& chip_text(origin_chip_view_->host_label_text()); | |
785 // If the chip is clicked, the omnibox text will become the toolbar model's | |
786 // formatted URL. We can't ask the omnibox for its current text, because | |
787 // while the chip is visible the current text is empty. | |
788 size_t prefix_end = 0; | |
789 const base::string16& omnibox_text( | |
790 GetToolbarModel()->GetFormattedURL(&prefix_end)); | |
791 // Do a case-insensitive search to better match cases like | |
792 // "Settings" <-> "chrome://settings". Skip any pre-hostname text. | |
793 size_t chip_text_offset = std::search( | |
794 omnibox_text.begin() + prefix_end, omnibox_text.end(), | |
795 chip_text.begin(), chip_text.end(), | |
796 base::CaseInsensitiveCompare<base::char16>()) - omnibox_text.begin(); | |
797 // If we couldn't find the chip text, try checking whether the omnibox text | |
798 // starts with it, as is true for e.g. file: URLs. | |
799 if ((chip_text_offset >= omnibox_text.length()) && | |
800 StartsWith(omnibox_text, chip_text, true)) | |
801 chip_text_offset = 0; | |
802 const gfx::FontList& font_list = omnibox_view_->GetFontList(); | |
803 const int chip_text_width = gfx::GetStringWidth(chip_text, font_list); | |
804 const int old_starting_offset = starting_omnibox_offset_; | |
805 const int old_starting_leading_inset = starting_omnibox_leading_inset_; | |
806 const int old_ending_width = ending_omnibox_width_; | |
807 starting_omnibox_offset_ = current_omnibox_offset_ = 0; | |
808 starting_omnibox_leading_inset_ = current_omnibox_leading_inset_ = 0; | |
809 ending_omnibox_width_ = gfx::GetStringWidth(omnibox_text, font_list); | |
810 if (chip_text_offset < omnibox_text.length()) { | |
811 if (base::i18n::IsRTL()) | |
812 chip_text_offset += chip_text.length(); | |
813 base::string16 extra_omnibox_text(base::i18n::IsRTL() ? | |
814 omnibox_text.substr(chip_text_offset) : | |
815 omnibox_text.substr(0, chip_text_offset)); | |
816 starting_omnibox_leading_inset_ = | |
817 gfx::GetStringWidth(extra_omnibox_text, font_list); | |
818 starting_omnibox_offset_ = origin_chip_view_->HostLabelOffset() - | |
819 starting_omnibox_leading_inset_; | |
820 current_omnibox_width_ = chip_text_width; | |
821 } else { | |
822 // If the chip text wasn't found in the omnibox text, then instead of | |
823 // starting the show animation clipped to the "hostname", we'll start with | |
824 // the entire omnibox text visible, clipped to the remaining chip width, and | |
825 // only animate any necessary expansion of that width, without moving the | |
826 // omnibox bounds. | |
827 current_omnibox_width_ = origin_chip_view_->WidthFromStartOfLabels(); | |
828 } | |
829 | |
830 // End the animations immediately if the parameters have changed. | |
831 if ((starting_omnibox_offset_ != old_starting_offset) || | |
832 (starting_omnibox_leading_inset_ != old_starting_leading_inset) || | |
833 (ending_omnibox_width_ != old_ending_width)) | |
834 EndOriginChipAnimations(true); | |
835 | |
836 // Also end the animations immediately if there's nothing to animate (but do | |
837 // allow the chip to fade back in). | |
838 const ui::NativeTheme* native_theme = GetNativeTheme(); | |
839 const SkColor ending_selection_text_color = native_theme->GetSystemColor( | |
840 ui::NativeTheme::kColorId_TextfieldSelectionColor); | |
841 const SkColor ending_selection_background_color = | |
842 native_theme->GetSystemColor( | |
843 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); | |
844 if ((starting_omnibox_offset_ == 0) && | |
845 (starting_omnibox_leading_inset_ == 0) && | |
846 (ending_omnibox_width_ == chip_text_width) && | |
847 (hide_url_animation_->is_animating() || | |
848 ((ending_selection_text_color == | |
849 origin_chip_view_->pressed_text_color()) && | |
850 (ending_selection_background_color == | |
851 origin_chip_view_->pressed_background_color())))) | |
852 EndOriginChipAnimations(false); | |
853 | |
854 if (show_url_animation_->is_animating()) { | |
855 omnibox_view_->SetSelectionTextColor(gfx::Tween::ColorValueBetween( | |
856 show_url_animation_->GetCurrentValue(), | |
857 origin_chip_view_->pressed_text_color(), | |
858 ending_selection_text_color)); | |
859 omnibox_view_->SetSelectionBackgroundColor(gfx::Tween::ColorValueBetween( | |
860 show_url_animation_->GetCurrentValue(), | |
861 origin_chip_view_->pressed_background_color(), | |
862 ending_selection_background_color)); | |
863 current_omnibox_offset_ = | |
864 show_url_animation_->CurrentValueBetween(starting_omnibox_offset_, 0); | |
865 current_omnibox_leading_inset_ = show_url_animation_->CurrentValueBetween( | |
866 starting_omnibox_leading_inset_, 0); | |
867 current_omnibox_width_ = show_url_animation_->CurrentValueBetween( | |
868 chip_text_width, ending_omnibox_width_); | |
869 } else if (hide_url_animation_->is_animating()) { | |
870 current_omnibox_offset_ = | |
871 hide_url_animation_->CurrentValueBetween(0, starting_omnibox_offset_); | |
872 current_omnibox_leading_inset_ = hide_url_animation_->CurrentValueBetween( | |
873 0, starting_omnibox_leading_inset_); | |
874 current_omnibox_width_ = hide_url_animation_->CurrentValueBetween( | |
875 ending_omnibox_width_, chip_text_width); | |
876 } | |
877 // Contract |available_width| as necessary, but never expand it. This way, | |
878 // we'll never draw suggested text at first and then have it disappear | |
879 // midway through the animation. | |
880 if (current_omnibox_offset_ > 0) | |
881 available_width -= current_omnibox_offset_; | |
882 location_bounds.Inset(current_omnibox_offset_, 0, 0, 0); | |
883 | |
884 // Layout out the suggested text view right aligned to the location | 742 // Layout out the suggested text view right aligned to the location |
885 // entry. Only show the suggested text if we can fit the text from one | 743 // entry. Only show the suggested text if we can fit the text from one |
886 // character before the end of the selection to the end of the text and the | 744 // character before the end of the selection to the end of the text and the |
887 // suggested text. If we can't it means either the suggested text is too big, | 745 // suggested text. If we can't it means either the suggested text is too big, |
888 // or the user has scrolled. | 746 // or the user has scrolled. |
889 | 747 |
890 // TODO(sky): We could potentially adjust this to take into account suggested | 748 // TODO(sky): We could potentially adjust this to take into account suggested |
891 // text to force using minimum size if necessary, but currently the chance of | 749 // text to force using minimum size if necessary, but currently the chance of |
892 // showing keyword hints and suggested text is minimal and we're not confident | 750 // showing keyword hints and suggested text is minimal and we're not confident |
893 // this is the right approach for suggested text. | 751 // this is the right approach for suggested text. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 omnibox_view_->Update(); | 849 omnibox_view_->Update(); |
992 | 850 |
993 OnChanged(); // NOTE: Calls Layout(). | 851 OnChanged(); // NOTE: Calls Layout(). |
994 } | 852 } |
995 | 853 |
996 void LocationBarView::ResetTabState(WebContents* contents) { | 854 void LocationBarView::ResetTabState(WebContents* contents) { |
997 omnibox_view_->ResetTabState(contents); | 855 omnibox_view_->ResetTabState(contents); |
998 } | 856 } |
999 | 857 |
1000 void LocationBarView::ShowURL() { | 858 void LocationBarView::ShowURL() { |
1001 // Start the animation before calling ShowURL(), since the latter eventually | |
1002 // calls back to Layout(), and if the animation is not marked as "running", | |
1003 // we'll draw the omnibox in its final position briefly until the first | |
1004 // animation callback reaches us. | |
1005 if (chrome::ShouldDisplayOriginChip()) { | |
1006 // If we're currently hiding, reverse the hide by swapping to the show | |
1007 // animation, offset so that the text is in the same position. | |
1008 if (hide_url_animation_->is_animating()) { | |
1009 const double show_value = GetValueForAnimation(false); | |
1010 hide_url_animation_->Reset(); | |
1011 show_url_animation_->Show(); | |
1012 // This must be done after calling Show() and is not equivalent to | |
1013 // calling Reset(n) before Show(); Reset() would have caused the entire | |
1014 // animation curve (and time) to run between this value and the final | |
1015 // value, whereas Show() + SetCurrentValue() skips the animation forward | |
1016 // to the supplied value. | |
1017 show_url_animation_->SetCurrentValue(show_value); | |
1018 } else { | |
1019 show_url_animation_->Show(); | |
1020 } | |
1021 } | |
1022 omnibox_view_->ShowURL(); | 859 omnibox_view_->ShowURL(); |
1023 } | 860 } |
1024 | 861 |
1025 void LocationBarView::EndOriginChipAnimations(bool cancel_fade) { | |
1026 show_url_animation_->End(); | |
1027 hide_url_animation_->End(); | |
1028 if (cancel_fade) | |
1029 origin_chip_view_->CancelFade(); | |
1030 } | |
1031 | |
1032 ToolbarModel* LocationBarView::GetToolbarModel() { | 862 ToolbarModel* LocationBarView::GetToolbarModel() { |
1033 return delegate_->GetToolbarModel(); | 863 return delegate_->GetToolbarModel(); |
1034 } | 864 } |
1035 | 865 |
1036 WebContents* LocationBarView::GetWebContents() { | 866 WebContents* LocationBarView::GetWebContents() { |
1037 return delegate_->GetWebContents(); | 867 return delegate_->GetWebContents(); |
1038 } | 868 } |
1039 | 869 |
1040 //////////////////////////////////////////////////////////////////////////////// | 870 //////////////////////////////////////////////////////////////////////////////// |
1041 // LocationBarView, private: | 871 // LocationBarView, private: |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 return suggested_text_view_->visible() && | 1038 return suggested_text_view_->visible() && |
1209 !suggested_text_view_->size().IsEmpty(); | 1039 !suggested_text_view_->size().IsEmpty(); |
1210 } | 1040 } |
1211 | 1041 |
1212 bool LocationBarView::ShouldShowKeywordBubble() const { | 1042 bool LocationBarView::ShouldShowKeywordBubble() const { |
1213 return !omnibox_view_->model()->keyword().empty() && | 1043 return !omnibox_view_->model()->keyword().empty() && |
1214 !omnibox_view_->model()->is_keyword_hint(); | 1044 !omnibox_view_->model()->is_keyword_hint(); |
1215 } | 1045 } |
1216 | 1046 |
1217 bool LocationBarView::ShouldShowEVBubble() const { | 1047 bool LocationBarView::ShouldShowEVBubble() const { |
1218 return !chrome::ShouldDisplayOriginChip() && | 1048 return |
1219 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); | 1049 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); |
1220 } | 1050 } |
1221 | 1051 |
1222 double LocationBarView::GetValueForAnimation(bool hide) const { | |
1223 int calculated_offset; | |
1224 const gfx::Tween::Type tween_type = hide ? kHideTweenType : kShowTweenType; | |
1225 int start_offset = starting_omnibox_offset_, end_offset = 0; | |
1226 if (hide) | |
1227 std::swap(start_offset, end_offset); | |
1228 const int desired_offset = abs(current_omnibox_offset_); | |
1229 // Binary-search the value space (0 <= value <= 1) to find the appropriate | |
1230 // position. We only bother to iterate to within 1/64 of the desired value, | |
1231 // because the longer of the two animations will only run for twelve frames | |
1232 // anyway (200 ms * 60 Hz), so at this point we'll have a maximum error of | |
1233 // less than a fifth of an animation frame, which the user isn't going to | |
1234 // notice. | |
1235 // | |
1236 // We have to use this method because Tween::CalculateValue() is not | |
1237 // necessarily easily invertible. Luckily, this only runs when the user | |
1238 // reverses the animation (rare), and the limit on how many iterations we'll | |
1239 // do ensures the cost is unnoticeable. | |
1240 double value = 0.5; | |
1241 double step = value / 2; | |
1242 do { | |
1243 calculated_offset = abs(gfx::Tween::IntValueBetween( | |
1244 gfx::Tween::CalculateValue(tween_type, value), start_offset, | |
1245 end_offset)); | |
1246 if (calculated_offset < desired_offset) | |
1247 value += step; | |
1248 else if (calculated_offset > desired_offset) | |
1249 value -= step; | |
1250 step /= 2; | |
1251 } while ((calculated_offset != desired_offset) && (step >= (1.0 / 64))); | |
1252 return value; | |
1253 } | |
1254 | |
1255 void LocationBarView::ResetShowAnimationAndColors() { | |
1256 show_url_animation_->Reset(); | |
1257 omnibox_view_->UseDefaultSelectionTextColor(); | |
1258 omnibox_view_->UseDefaultSelectionBackgroundColor(); | |
1259 } | |
1260 | |
1261 //////////////////////////////////////////////////////////////////////////////// | 1052 //////////////////////////////////////////////////////////////////////////////// |
1262 // LocationBarView, private LocationBar implementation: | 1053 // LocationBarView, private LocationBar implementation: |
1263 | 1054 |
1264 void LocationBarView::ShowFirstRunBubble() { | 1055 void LocationBarView::ShowFirstRunBubble() { |
1265 // Wait until search engines have loaded to show the first run bubble. | 1056 // Wait until search engines have loaded to show the first run bubble. |
1266 TemplateURLService* url_service = | 1057 TemplateURLService* url_service = |
1267 TemplateURLServiceFactory::GetForProfile(profile()); | 1058 TemplateURLServiceFactory::GetForProfile(profile()); |
1268 if (!url_service->loaded()) { | 1059 if (!url_service->loaded()) { |
1269 template_url_service_ = url_service; | 1060 template_url_service_ = url_service; |
1270 template_url_service_->AddObserver(this); | 1061 template_url_service_->AddObserver(this); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 SchedulePaint(); | 1147 SchedulePaint(); |
1357 } | 1148 } |
1358 | 1149 |
1359 void LocationBarView::UpdateGeneratedCreditCardView() { | 1150 void LocationBarView::UpdateGeneratedCreditCardView() { |
1360 generated_credit_card_view_->Update(); | 1151 generated_credit_card_view_->Update(); |
1361 Layout(); | 1152 Layout(); |
1362 SchedulePaint(); | 1153 SchedulePaint(); |
1363 } | 1154 } |
1364 | 1155 |
1365 void LocationBarView::SaveStateToContents(WebContents* contents) { | 1156 void LocationBarView::SaveStateToContents(WebContents* contents) { |
1366 // If we're about to switch tabs, complete any current animations, so that if | |
1367 // the user is in the midst of hiding the URL, when he returns to this tab, | |
1368 // the URL will be hidden rather than shown. | |
1369 // NOTE: This must be called before SaveStateToTab(). | |
1370 EndOriginChipAnimations(true); | |
1371 omnibox_view_->SaveStateToTab(contents); | 1157 omnibox_view_->SaveStateToTab(contents); |
1372 } | 1158 } |
1373 | 1159 |
1374 const OmniboxView* LocationBarView::GetOmniboxView() const { | 1160 const OmniboxView* LocationBarView::GetOmniboxView() const { |
1375 return omnibox_view_; | 1161 return omnibox_view_; |
1376 } | 1162 } |
1377 | 1163 |
1378 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { | 1164 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { |
1379 return this; | 1165 return this; |
1380 } | 1166 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | 1266 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
1481 } | 1267 } |
1482 | 1268 |
1483 // The border itself will be drawn in PaintChildren() since it includes an | 1269 // The border itself will be drawn in PaintChildren() since it includes an |
1484 // inner shadow which should be drawn over the contents. | 1270 // inner shadow which should be drawn over the contents. |
1485 } | 1271 } |
1486 | 1272 |
1487 void LocationBarView::PaintChildren(gfx::Canvas* canvas, | 1273 void LocationBarView::PaintChildren(gfx::Canvas* canvas, |
1488 const views::CullSet& cull_set) { | 1274 const views::CullSet& cull_set) { |
1489 // Paint all the children except for the omnibox itself, which may need to be | 1275 // Paint all the children except for the omnibox itself, which may need to be |
1490 // clipped if it's animating in, and the origin chip and the search button, | 1276 // clipped if it's animating in, and the search button, which will be painted |
1491 // which will be painted after the border. | 1277 // after the border. |
1492 for (int i = 0, count = child_count(); i < count; ++i) { | 1278 for (int i = 0, count = child_count(); i < count; ++i) { |
1493 views::View* child = child_at(i); | 1279 views::View* child = child_at(i); |
1494 if (!child->layer() && (child != omnibox_view_) && | 1280 if (!child->layer() && (child != omnibox_view_) && |
1495 (child != origin_chip_view_) && (child != search_button_)) | 1281 (child != search_button_)) |
1496 child->Paint(canvas, cull_set); | 1282 child->Paint(canvas, cull_set); |
1497 } | 1283 } |
1498 | 1284 |
1499 { | 1285 { |
1500 gfx::ScopedCanvas scoped_canvas(canvas); | 1286 gfx::ScopedCanvas scoped_canvas(canvas); |
1501 if (show_url_animation_->is_animating() || | |
1502 hide_url_animation_->is_animating()) { | |
1503 gfx::Rect clip_rect(omnibox_view_->bounds()); | |
1504 clip_rect.Inset(current_omnibox_leading_inset_, 0, 0, 0); | |
1505 clip_rect.set_width(current_omnibox_width_); | |
1506 clip_rect.set_x(GetMirroredXForRect(clip_rect)); | |
1507 canvas->ClipRect(clip_rect); | |
1508 } | |
1509 omnibox_view_->Paint(canvas, cull_set); | 1287 omnibox_view_->Paint(canvas, cull_set); |
1510 } | 1288 } |
1511 | 1289 |
1512 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need | 1290 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need |
1513 // the focus rect to appear on top of children we paint here rather than | 1291 // the focus rect to appear on top of children we paint here rather than |
1514 // OnPaint(). | 1292 // OnPaint(). |
1515 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. | 1293 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. |
1516 if (show_focus_rect_ && HasFocus()) | 1294 if (show_focus_rect_ && HasFocus()) |
1517 canvas->DrawFocusRect(omnibox_view_->bounds()); | 1295 canvas->DrawFocusRect(omnibox_view_->bounds()); |
1518 | 1296 |
1519 // Maximized popup windows don't draw the horizontal edges. We implement this | 1297 // Maximized popup windows don't draw the horizontal edges. We implement this |
1520 // by simply expanding the paint area outside the view by the edge thickness. | 1298 // by simply expanding the paint area outside the view by the edge thickness. |
1521 gfx::Rect border_rect(GetContentsBounds()); | 1299 gfx::Rect border_rect(GetContentsBounds()); |
1522 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) | 1300 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) |
1523 border_rect.Inset(-kPopupEdgeThickness, 0); | 1301 border_rect.Inset(-kPopupEdgeThickness, 0); |
1524 views::Painter::PaintPainterAt(canvas, border_painter_.get(), border_rect); | 1302 views::Painter::PaintPainterAt(canvas, border_painter_.get(), border_rect); |
1525 | 1303 |
1526 // The origin chip and the search button must be painted after the border so | 1304 // The search button must be painted after the border so that the border |
1527 // that the border shadow is not drawn over them. | 1305 // shadow is not drawn over them. |
1528 origin_chip_view_->Paint(canvas, cull_set); | |
1529 search_button_->Paint(canvas, cull_set); | 1306 search_button_->Paint(canvas, cull_set); |
1530 } | 1307 } |
1531 | 1308 |
1532 //////////////////////////////////////////////////////////////////////////////// | 1309 //////////////////////////////////////////////////////////////////////////////// |
1533 // LocationBarView, private views::ButtonListener implementation: | 1310 // LocationBarView, private views::ButtonListener implementation: |
1534 | 1311 |
1535 void LocationBarView::ButtonPressed(views::Button* sender, | 1312 void LocationBarView::ButtonPressed(views::Button* sender, |
1536 const ui::Event& event) { | 1313 const ui::Event& event) { |
1537 if (sender == mic_search_view_) { | 1314 if (sender == mic_search_view_) { |
1538 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); | 1315 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); |
(...skipping 22 matching lines...) Expand all Loading... |
1561 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), | 1338 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), |
1562 web_contents->GetTitle(), | 1339 web_contents->GetTitle(), |
1563 favicon, | 1340 favicon, |
1564 NULL, | 1341 NULL, |
1565 data, | 1342 data, |
1566 sender->GetWidget()); | 1343 sender->GetWidget()); |
1567 } | 1344 } |
1568 | 1345 |
1569 int LocationBarView::GetDragOperationsForView(views::View* sender, | 1346 int LocationBarView::GetDragOperationsForView(views::View* sender, |
1570 const gfx::Point& p) { | 1347 const gfx::Point& p) { |
1571 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_) || | 1348 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_)); |
1572 (sender == origin_chip_view_)); | |
1573 WebContents* web_contents = delegate_->GetWebContents(); | 1349 WebContents* web_contents = delegate_->GetWebContents(); |
1574 return (web_contents && web_contents->GetURL().is_valid() && | 1350 return (web_contents && web_contents->GetURL().is_valid() && |
1575 (!GetOmniboxView()->IsEditingOrEmpty() || | 1351 (!GetOmniboxView()->IsEditingOrEmpty())) ? |
1576 sender == origin_chip_view_)) ? | |
1577 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) : | 1352 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) : |
1578 ui::DragDropTypes::DRAG_NONE; | 1353 ui::DragDropTypes::DRAG_NONE; |
1579 } | 1354 } |
1580 | 1355 |
1581 bool LocationBarView::CanStartDragForView(View* sender, | 1356 bool LocationBarView::CanStartDragForView(View* sender, |
1582 const gfx::Point& press_pt, | 1357 const gfx::Point& press_pt, |
1583 const gfx::Point& p) { | 1358 const gfx::Point& p) { |
1584 return true; | 1359 return true; |
1585 } | 1360 } |
1586 | 1361 |
(...skipping 10 matching lines...) Expand all Loading... |
1597 chrome::GetDisplaySearchButtonConditions(); | 1372 chrome::GetDisplaySearchButtonConditions(); |
1598 bool meets_conditions = | 1373 bool meets_conditions = |
1599 (conditions == chrome::DISPLAY_SEARCH_BUTTON_ALWAYS) || | 1374 (conditions == chrome::DISPLAY_SEARCH_BUTTON_ALWAYS) || |
1600 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) && | 1375 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) && |
1601 (toolbar_model->WouldPerformSearchTermReplacement(true) || | 1376 (toolbar_model->WouldPerformSearchTermReplacement(true) || |
1602 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && | 1377 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && |
1603 toolbar_model->input_in_progress()))); | 1378 toolbar_model->input_in_progress()))); |
1604 search_button_->SetVisible(!is_popup_mode_ && meets_conditions); | 1379 search_button_->SetVisible(!is_popup_mode_ && meets_conditions); |
1605 search_button_->UpdateIcon(icon_id == IDR_OMNIBOX_SEARCH); | 1380 search_button_->UpdateIcon(icon_id == IDR_OMNIBOX_SEARCH); |
1606 | 1381 |
1607 origin_chip_view_->OnChanged(); | |
1608 | |
1609 Layout(); | 1382 Layout(); |
1610 SchedulePaint(); | 1383 SchedulePaint(); |
1611 } | 1384 } |
1612 | 1385 |
1613 void LocationBarView::OnSetFocus() { | 1386 void LocationBarView::OnSetFocus() { |
1614 GetFocusManager()->SetFocusedView(this); | 1387 GetFocusManager()->SetFocusedView(this); |
1615 } | 1388 } |
1616 | 1389 |
1617 InstantController* LocationBarView::GetInstant() { | 1390 InstantController* LocationBarView::GetInstant() { |
1618 return delegate_->GetInstant(); | 1391 return delegate_->GetInstant(); |
1619 } | 1392 } |
1620 | 1393 |
1621 const ToolbarModel* LocationBarView::GetToolbarModel() const { | 1394 const ToolbarModel* LocationBarView::GetToolbarModel() const { |
1622 return delegate_->GetToolbarModel(); | 1395 return delegate_->GetToolbarModel(); |
1623 } | 1396 } |
1624 | 1397 |
1625 void LocationBarView::HideURL() { | |
1626 DCHECK(chrome::ShouldDisplayOriginChip()); | |
1627 | |
1628 // If we're currently showing, reverse the hide by swapping to the hide | |
1629 // animation, offset so that the text is in the same position. | |
1630 if (show_url_animation_->is_animating()) { | |
1631 const double hide_value = GetValueForAnimation(true); | |
1632 ResetShowAnimationAndColors(); | |
1633 hide_url_animation_->Show(); | |
1634 // This must be done after calling Show() and is not equivalent to Reset(n); | |
1635 // see comments in ShowURL(). | |
1636 hide_url_animation_->SetCurrentValue(hide_value); | |
1637 } else { | |
1638 hide_url_animation_->Show(); | |
1639 } | |
1640 } | |
1641 | |
1642 //////////////////////////////////////////////////////////////////////////////// | 1398 //////////////////////////////////////////////////////////////////////////////// |
1643 // LocationBarView, private DropdownBarHostDelegate implementation: | 1399 // LocationBarView, private DropdownBarHostDelegate implementation: |
1644 | 1400 |
1645 void LocationBarView::SetFocusAndSelection(bool select_all) { | 1401 void LocationBarView::SetFocusAndSelection(bool select_all) { |
1646 FocusLocation(select_all); | 1402 FocusLocation(select_all); |
1647 } | 1403 } |
1648 | 1404 |
1649 void LocationBarView::SetAnimationOffset(int offset) { | 1405 void LocationBarView::SetAnimationOffset(int offset) { |
1650 dropdown_animation_offset_ = offset; | 1406 dropdown_animation_offset_ = offset; |
1651 } | 1407 } |
1652 | 1408 |
1653 //////////////////////////////////////////////////////////////////////////////// | 1409 //////////////////////////////////////////////////////////////////////////////// |
1654 // LocationBarView, private gfx::AnimationDelegate implementation: | |
1655 | |
1656 void LocationBarView::AnimationProgressed(const gfx::Animation* animation) { | |
1657 DCHECK((animation == show_url_animation_.get()) || | |
1658 (animation == hide_url_animation_.get())); | |
1659 Layout(); | |
1660 SchedulePaint(); | |
1661 } | |
1662 | |
1663 void LocationBarView::AnimationEnded(const gfx::Animation* animation) { | |
1664 if (animation == show_url_animation_.get()) { | |
1665 ResetShowAnimationAndColors(); | |
1666 Layout(); | |
1667 SchedulePaint(); | |
1668 } else { | |
1669 DCHECK(animation == hide_url_animation_.get()); | |
1670 hide_url_animation_->Reset(); | |
1671 origin_chip_view_->FadeIn(); | |
1672 omnibox_view_->HideURL(); // Calls OnChanged(), triggering layout. | |
1673 } | |
1674 } | |
1675 | |
1676 //////////////////////////////////////////////////////////////////////////////// | |
1677 // LocationBarView, private TemplateURLServiceObserver implementation: | 1410 // LocationBarView, private TemplateURLServiceObserver implementation: |
1678 | 1411 |
1679 void LocationBarView::OnTemplateURLServiceChanged() { | 1412 void LocationBarView::OnTemplateURLServiceChanged() { |
1680 template_url_service_->RemoveObserver(this); | 1413 template_url_service_->RemoveObserver(this); |
1681 template_url_service_ = NULL; | 1414 template_url_service_ = NULL; |
1682 // If the browser is no longer active, let's not show the info bubble, as this | 1415 // If the browser is no longer active, let's not show the info bubble, as this |
1683 // would make the browser the active window again. | 1416 // would make the browser the active window again. |
1684 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1417 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
1685 ShowFirstRunBubble(); | 1418 ShowFirstRunBubble(); |
1686 } | 1419 } |
1687 | 1420 |
1688 //////////////////////////////////////////////////////////////////////////////// | 1421 //////////////////////////////////////////////////////////////////////////////// |
1689 // LocationBarView, private SearchModelObserver implementation: | 1422 // LocationBarView, private SearchModelObserver implementation: |
1690 | 1423 |
1691 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1424 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
1692 const SearchModel::State& new_state) { | 1425 const SearchModel::State& new_state) { |
1693 const bool visible = !GetToolbarModel()->input_in_progress() && | 1426 const bool visible = !GetToolbarModel()->input_in_progress() && |
1694 new_state.voice_search_supported; | 1427 new_state.voice_search_supported; |
1695 if (mic_search_view_->visible() != visible) { | 1428 if (mic_search_view_->visible() != visible) { |
1696 mic_search_view_->SetVisible(visible); | 1429 mic_search_view_->SetVisible(visible); |
1697 Layout(); | 1430 Layout(); |
1698 } | 1431 } |
1699 } | 1432 } |
OLD | NEW |