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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 94 |
96 #if !defined(OS_CHROMEOS) | 95 #if !defined(OS_CHROMEOS) |
97 #include "chrome/browser/ui/views/first_run_bubble.h" | 96 #include "chrome/browser/ui/views/first_run_bubble.h" |
98 #endif | 97 #endif |
99 | 98 |
100 using content::WebContents; | 99 using content::WebContents; |
101 using views::View; | 100 using views::View; |
102 | 101 |
103 namespace { | 102 namespace { |
104 | 103 |
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 | 104 // 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 | 105 // images, but to align things, the search button needs to be inset horizontally |
110 // by 1 px. | 106 // by 1 px. |
111 const int kSearchButtonInset = 1; | 107 const int kSearchButtonInset = 1; |
112 | 108 |
113 int GetEditLeadingInternalSpace() { | 109 int GetEditLeadingInternalSpace() { |
114 // The textfield has 1 px of whitespace before the text in the RTL case only. | 110 // The textfield has 1 px of whitespace before the text in the RTL case only. |
115 return base::i18n::IsRTL() ? 1 : 0; | 111 return base::i18n::IsRTL() ? 1 : 0; |
116 } | 112 } |
117 | 113 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 LocationBarView::LocationBarView(Browser* browser, | 149 LocationBarView::LocationBarView(Browser* browser, |
154 Profile* profile, | 150 Profile* profile, |
155 CommandUpdater* command_updater, | 151 CommandUpdater* command_updater, |
156 Delegate* delegate, | 152 Delegate* delegate, |
157 bool is_popup_mode) | 153 bool is_popup_mode) |
158 : LocationBar(profile), | 154 : LocationBar(profile), |
159 OmniboxEditController(command_updater), | 155 OmniboxEditController(command_updater), |
160 browser_(browser), | 156 browser_(browser), |
161 omnibox_view_(NULL), | 157 omnibox_view_(NULL), |
162 delegate_(delegate), | 158 delegate_(delegate), |
163 origin_chip_view_(NULL), | |
164 location_icon_view_(NULL), | 159 location_icon_view_(NULL), |
165 ev_bubble_view_(NULL), | 160 ev_bubble_view_(NULL), |
166 ime_inline_autocomplete_view_(NULL), | 161 ime_inline_autocomplete_view_(NULL), |
167 selected_keyword_view_(NULL), | 162 selected_keyword_view_(NULL), |
168 suggested_text_view_(NULL), | 163 suggested_text_view_(NULL), |
169 keyword_hint_view_(NULL), | 164 keyword_hint_view_(NULL), |
170 mic_search_view_(NULL), | 165 mic_search_view_(NULL), |
171 zoom_view_(NULL), | 166 zoom_view_(NULL), |
172 generated_credit_card_view_(NULL), | 167 generated_credit_card_view_(NULL), |
173 open_pdf_in_reader_view_(NULL), | 168 open_pdf_in_reader_view_(NULL), |
174 manage_passwords_icon_view_(NULL), | 169 manage_passwords_icon_view_(NULL), |
175 translate_icon_view_(NULL), | 170 translate_icon_view_(NULL), |
176 star_view_(NULL), | 171 star_view_(NULL), |
177 search_button_(NULL), | 172 search_button_(NULL), |
178 is_popup_mode_(is_popup_mode), | 173 is_popup_mode_(is_popup_mode), |
179 show_focus_rect_(false), | 174 show_focus_rect_(false), |
180 template_url_service_(NULL), | 175 template_url_service_(NULL), |
181 dropdown_animation_offset_(0), | 176 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) { | 177 web_contents_null_at_last_refresh_(true) { |
189 edit_bookmarks_enabled_.Init( | 178 edit_bookmarks_enabled_.Init( |
190 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), | 179 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), |
191 base::Bind(&LocationBarView::Update, base::Unretained(this), | 180 base::Bind(&LocationBarView::Update, base::Unretained(this), |
192 static_cast<content::WebContents*>(NULL))); | 181 static_cast<content::WebContents*>(NULL))); |
193 | 182 |
194 if (browser_) | 183 if (browser_) |
195 browser_->search_model()->AddObserver(this); | 184 browser_->search_model()->AddObserver(this); |
196 } | 185 } |
197 | 186 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); | 253 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); |
265 ime_inline_autocomplete_view_->set_background( | 254 ime_inline_autocomplete_view_->set_background( |
266 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( | 255 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
267 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); | 256 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); |
268 ime_inline_autocomplete_view_->SetEnabledColor( | 257 ime_inline_autocomplete_view_->SetEnabledColor( |
269 GetNativeTheme()->GetSystemColor( | 258 GetNativeTheme()->GetSystemColor( |
270 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | 259 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
271 ime_inline_autocomplete_view_->SetVisible(false); | 260 ime_inline_autocomplete_view_->SetVisible(false); |
272 AddChildView(ime_inline_autocomplete_view_); | 261 AddChildView(ime_inline_autocomplete_view_); |
273 | 262 |
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); | 263 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); |
280 selected_keyword_view_ = new SelectedKeywordView( | 264 selected_keyword_view_ = new SelectedKeywordView( |
281 bubble_font_list, text_color, background_color, profile()); | 265 bubble_font_list, text_color, background_color, profile()); |
282 AddChildView(selected_keyword_view_); | 266 AddChildView(selected_keyword_view_); |
283 | 267 |
284 suggested_text_view_ = new views::Label(base::string16(), font_list); | 268 suggested_text_view_ = new views::Label(base::string16(), font_list); |
285 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 269 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
286 suggested_text_view_->SetAutoColorReadabilityEnabled(false); | 270 suggested_text_view_->SetAutoColorReadabilityEnabled(false); |
287 suggested_text_view_->SetEnabledColor(GetColor( | 271 suggested_text_view_->SetEnabledColor(GetColor( |
288 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); | 272 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 AddChildView(translate_icon_view_); | 320 AddChildView(translate_icon_view_); |
337 | 321 |
338 star_view_ = new StarView(command_updater(), browser_); | 322 star_view_ = new StarView(command_updater(), browser_); |
339 star_view_->SetVisible(false); | 323 star_view_->SetVisible(false); |
340 AddChildView(star_view_); | 324 AddChildView(star_view_); |
341 | 325 |
342 search_button_ = new SearchButton(this); | 326 search_button_ = new SearchButton(this); |
343 search_button_->SetVisible(false); | 327 search_button_->SetVisible(false); |
344 AddChildView(search_button_); | 328 AddChildView(search_button_); |
345 | 329 |
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 | 330 // Initialize the location entry. We do this to avoid a black flash which is |
355 // visible when the location entry has just been initialized. | 331 // visible when the location entry has just been initialized. |
356 Update(NULL); | 332 Update(NULL); |
357 } | 333 } |
358 | 334 |
359 bool LocationBarView::IsInitialized() const { | 335 bool LocationBarView::IsInitialized() const { |
360 return omnibox_view_ != NULL; | 336 return omnibox_view_ != NULL; |
361 } | 337 } |
362 | 338 |
363 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, | 339 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 if (star_view_) | 437 if (star_view_) |
462 star_view_->SetToggled(on); | 438 star_view_->SetToggled(on); |
463 } | 439 } |
464 | 440 |
465 void LocationBarView::SetTranslateIconToggled(bool on) { | 441 void LocationBarView::SetTranslateIconToggled(bool on) { |
466 translate_icon_view_->SetToggled(on); | 442 translate_icon_view_->SetToggled(on); |
467 } | 443 } |
468 | 444 |
469 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { | 445 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { |
470 gfx::Point origin(omnibox_view_->bounds().origin()); | 446 gfx::Point origin(omnibox_view_->bounds().origin()); |
471 origin.set_x(GetMirroredXInView(origin.x() - current_omnibox_offset_)); | 447 origin.set_x(GetMirroredXInView(origin.x())); |
472 views::View::ConvertPointToScreen(this, &origin); | 448 views::View::ConvertPointToScreen(this, &origin); |
473 return origin; | 449 return origin; |
474 } | 450 } |
475 | 451 |
476 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { | 452 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { |
477 ime_inline_autocomplete_view_->SetText(text); | 453 ime_inline_autocomplete_view_->SetText(text); |
478 ime_inline_autocomplete_view_->SetVisible(!text.empty()); | 454 ime_inline_autocomplete_view_->SetVisible(!text.empty()); |
479 } | 455 } |
480 | 456 |
481 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { | 457 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 // Compute minimum height. | 551 // Compute minimum height. |
576 gfx::Size min_size(border_painter_->GetMinimumSize()); | 552 gfx::Size min_size(border_painter_->GetMinimumSize()); |
577 if (!IsInitialized()) | 553 if (!IsInitialized()) |
578 return min_size; | 554 return min_size; |
579 gfx::Size search_button_min_size(search_button_->GetMinimumSize()); | 555 gfx::Size search_button_min_size(search_button_->GetMinimumSize()); |
580 min_size.SetToMax(search_button_min_size); | 556 min_size.SetToMax(search_button_min_size); |
581 | 557 |
582 // Compute width of omnibox-leading content. | 558 // Compute width of omnibox-leading content. |
583 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); | 559 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
584 int leading_width = horizontal_edge_thickness; | 560 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()) { | 561 if (ShouldShowKeywordBubble()) { |
590 // The selected keyword view can collapse completely. | 562 // The selected keyword view can collapse completely. |
591 } else if (ShouldShowEVBubble()) { | 563 } else if (ShouldShowEVBubble()) { |
592 leading_width += kBubblePadding + | 564 leading_width += kBubblePadding + |
593 ev_bubble_view_->GetMinimumSizeForLabelText( | 565 ev_bubble_view_->GetMinimumSizeForLabelText( |
594 GetToolbarModel()->GetEVCertName()).width(); | 566 GetToolbarModel()->GetEVCertName()).width(); |
595 } else if (!origin_chip_view_->visible()) { | 567 } else { |
596 leading_width += | 568 leading_width += |
597 kItemPadding + location_icon_view_->GetMinimumSize().width(); | 569 kItemPadding + location_icon_view_->GetMinimumSize().width(); |
598 } | 570 } |
599 | 571 |
600 // Compute width of omnibox-trailing content. | 572 // Compute width of omnibox-trailing content. |
601 int trailing_width = search_button_->visible() ? | 573 int trailing_width = search_button_->visible() ? |
602 (search_button_->GetMinimumSize().width() + kSearchButtonInset) : | 574 (search_button_->GetMinimumSize().width() + kSearchButtonInset) : |
603 horizontal_edge_thickness; | 575 horizontal_edge_thickness; |
604 trailing_width += IncrementalMinimumWidth(star_view_) + | 576 trailing_width += IncrementalMinimumWidth(star_view_) + |
605 IncrementalMinimumWidth(translate_icon_view_) + | 577 IncrementalMinimumWidth(translate_icon_view_) + |
(...skipping 11 matching lines...) Expand all Loading... |
617 | 589 |
618 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + | 590 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + |
619 2 * kItemPadding - omnibox_view_->GetInsets().width() + trailing_width); | 591 2 * kItemPadding - omnibox_view_->GetInsets().width() + trailing_width); |
620 return min_size; | 592 return min_size; |
621 } | 593 } |
622 | 594 |
623 void LocationBarView::Layout() { | 595 void LocationBarView::Layout() { |
624 if (!IsInitialized()) | 596 if (!IsInitialized()) |
625 return; | 597 return; |
626 | 598 |
627 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip()); | |
628 selected_keyword_view_->SetVisible(false); | 599 selected_keyword_view_->SetVisible(false); |
629 location_icon_view_->SetVisible(false); | 600 location_icon_view_->SetVisible(false); |
630 ev_bubble_view_->SetVisible(false); | 601 ev_bubble_view_->SetVisible(false); |
631 keyword_hint_view_->SetVisible(false); | 602 keyword_hint_view_->SetVisible(false); |
632 | 603 |
633 LocationBarLayout leading_decorations( | 604 LocationBarLayout leading_decorations( |
634 LocationBarLayout::LEFT_EDGE, | 605 LocationBarLayout::LEFT_EDGE, |
635 kItemPadding - omnibox_view_->GetInsets().left() - | 606 kItemPadding - omnibox_view_->GetInsets().left() - |
636 GetEditLeadingInternalSpace()); | 607 GetEditLeadingInternalSpace()); |
637 LocationBarLayout trailing_decorations( | 608 LocationBarLayout trailing_decorations( |
638 LocationBarLayout::RIGHT_EDGE, | 609 LocationBarLayout::RIGHT_EDGE, |
639 kItemPadding - omnibox_view_->GetInsets().right()); | 610 kItemPadding - omnibox_view_->GetInsets().right()); |
640 | 611 |
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; | 612 const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; |
652 const base::string16 keyword(omnibox_view_->model()->keyword()); | 613 const base::string16 keyword(omnibox_view_->model()->keyword()); |
653 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 614 // 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 | 615 // 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 | 616 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
656 // hits ctrl-d). | 617 // hits ctrl-d). |
657 const int location_height = GetInternalHeight(false); | 618 const int location_height = GetInternalHeight(false); |
658 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); | 619 const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); |
659 if (ShouldShowKeywordBubble()) { | 620 if (ShouldShowKeywordBubble()) { |
660 leading_decorations.AddDecoration(bubble_location_y, bubble_height, true, 0, | 621 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); | 638 selected_keyword_view_->set_is_extension_icon(false); |
678 } | 639 } |
679 } | 640 } |
680 } else if (ShouldShowEVBubble()) { | 641 } else if (ShouldShowEVBubble()) { |
681 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); | 642 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); |
682 // The largest fraction of the omnibox that can be taken by the EV bubble. | 643 // The largest fraction of the omnibox that can be taken by the EV bubble. |
683 const double kMaxBubbleFraction = 0.5; | 644 const double kMaxBubbleFraction = 0.5; |
684 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, | 645 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, |
685 kMaxBubbleFraction, kBubblePadding, | 646 kMaxBubbleFraction, kBubblePadding, |
686 kItemPadding, ev_bubble_view_); | 647 kItemPadding, ev_bubble_view_); |
687 } else if (!origin_chip_view_->visible()) { | 648 } else { |
688 leading_decorations.AddDecoration( | 649 leading_decorations.AddDecoration( |
689 vertical_edge_thickness(), location_height, | 650 vertical_edge_thickness(), location_height, |
690 location_icon_view_); | 651 location_icon_view_); |
691 } | 652 } |
692 | 653 |
693 if (star_view_->visible()) { | 654 if (star_view_->visible()) { |
694 trailing_decorations.AddDecoration( | 655 trailing_decorations.AddDecoration( |
695 vertical_edge_thickness(), location_height, star_view_); | 656 vertical_edge_thickness(), location_height, star_view_); |
696 } | 657 } |
697 if (translate_icon_view_->visible()) { | 658 if (translate_icon_view_->visible()) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 !omnibox_view_->IsImeComposing()) { | 703 !omnibox_view_->IsImeComposing()) { |
743 trailing_decorations.AddDecoration(vertical_edge_thickness(), | 704 trailing_decorations.AddDecoration(vertical_edge_thickness(), |
744 location_height, true, 0, kItemPadding, | 705 location_height, true, 0, kItemPadding, |
745 kItemPadding, keyword_hint_view_); | 706 kItemPadding, keyword_hint_view_); |
746 if (keyword_hint_view_->keyword() != keyword) | 707 if (keyword_hint_view_->keyword() != keyword) |
747 keyword_hint_view_->SetKeyword(keyword); | 708 keyword_hint_view_->SetKeyword(keyword); |
748 } | 709 } |
749 | 710 |
750 // Perform layout. | 711 // Perform layout. |
751 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); | 712 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
752 int full_width = width() - horizontal_edge_thickness - origin_chip_width; | 713 int full_width = width() - horizontal_edge_thickness; |
753 | 714 |
754 const gfx::Size search_button_size(search_button_->GetPreferredSize()); | 715 const gfx::Size search_button_size(search_button_->GetPreferredSize()); |
755 const int search_button_reserved_width = | 716 const int search_button_reserved_width = |
756 search_button_size.width() + kSearchButtonInset; | 717 search_button_size.width() + kSearchButtonInset; |
757 full_width -= search_button_->visible() ? | 718 full_width -= search_button_->visible() ? |
758 search_button_reserved_width : horizontal_edge_thickness; | 719 search_button_reserved_width : horizontal_edge_thickness; |
759 int entry_width = full_width; | 720 int entry_width = full_width; |
760 leading_decorations.LayoutPass1(&entry_width); | 721 leading_decorations.LayoutPass1(&entry_width); |
761 trailing_decorations.LayoutPass1(&entry_width); | 722 trailing_decorations.LayoutPass1(&entry_width); |
762 leading_decorations.LayoutPass2(&entry_width); | 723 leading_decorations.LayoutPass2(&entry_width); |
763 trailing_decorations.LayoutPass2(&entry_width); | 724 trailing_decorations.LayoutPass2(&entry_width); |
764 | 725 |
765 int location_needed_width = omnibox_view_->GetTextWidth(); | 726 int location_needed_width = omnibox_view_->GetTextWidth(); |
766 int available_width = entry_width - location_needed_width; | 727 int available_width = entry_width - location_needed_width; |
767 // The bounds must be wide enough for all the decorations to fit. | 728 // The bounds must be wide enough for all the decorations to fit. |
768 gfx::Rect location_bounds( | 729 gfx::Rect location_bounds( |
769 origin_chip_width + horizontal_edge_thickness, vertical_edge_thickness(), | 730 horizontal_edge_thickness, vertical_edge_thickness(), |
770 std::max(full_width, full_width - entry_width), location_height); | 731 std::max(full_width, full_width - entry_width), location_height); |
771 leading_decorations.LayoutPass3(&location_bounds, &available_width); | 732 leading_decorations.LayoutPass3(&location_bounds, &available_width); |
772 trailing_decorations.LayoutPass3(&location_bounds, &available_width); | 733 trailing_decorations.LayoutPass3(&location_bounds, &available_width); |
773 | 734 |
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 | 735 // 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 | 736 // 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 | 737 // 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, | 738 // suggested text. If we can't it means either the suggested text is too big, |
881 // or the user has scrolled. | 739 // or the user has scrolled. |
882 | 740 |
883 // TODO(sky): We could potentially adjust this to take into account suggested | 741 // 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 | 742 // 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 | 743 // showing keyword hints and suggested text is minimal and we're not confident |
886 // this is the right approach for suggested text. | 744 // this is the right approach for suggested text. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 omnibox_view_->Update(); | 842 omnibox_view_->Update(); |
985 | 843 |
986 OnChanged(); // NOTE: Calls Layout(). | 844 OnChanged(); // NOTE: Calls Layout(). |
987 } | 845 } |
988 | 846 |
989 void LocationBarView::ResetTabState(WebContents* contents) { | 847 void LocationBarView::ResetTabState(WebContents* contents) { |
990 omnibox_view_->ResetTabState(contents); | 848 omnibox_view_->ResetTabState(contents); |
991 } | 849 } |
992 | 850 |
993 void LocationBarView::ShowURL() { | 851 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(); | 852 omnibox_view_->ShowURL(); |
1016 } | 853 } |
1017 | 854 |
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() { | 855 ToolbarModel* LocationBarView::GetToolbarModel() { |
1026 return delegate_->GetToolbarModel(); | 856 return delegate_->GetToolbarModel(); |
1027 } | 857 } |
1028 | 858 |
1029 WebContents* LocationBarView::GetWebContents() { | 859 WebContents* LocationBarView::GetWebContents() { |
1030 return delegate_->GetWebContents(); | 860 return delegate_->GetWebContents(); |
1031 } | 861 } |
1032 | 862 |
1033 //////////////////////////////////////////////////////////////////////////////// | 863 //////////////////////////////////////////////////////////////////////////////// |
1034 // LocationBarView, private: | 864 // LocationBarView, private: |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 return suggested_text_view_->visible() && | 1027 return suggested_text_view_->visible() && |
1198 !suggested_text_view_->size().IsEmpty(); | 1028 !suggested_text_view_->size().IsEmpty(); |
1199 } | 1029 } |
1200 | 1030 |
1201 bool LocationBarView::ShouldShowKeywordBubble() const { | 1031 bool LocationBarView::ShouldShowKeywordBubble() const { |
1202 return !omnibox_view_->model()->keyword().empty() && | 1032 return !omnibox_view_->model()->keyword().empty() && |
1203 !omnibox_view_->model()->is_keyword_hint(); | 1033 !omnibox_view_->model()->is_keyword_hint(); |
1204 } | 1034 } |
1205 | 1035 |
1206 bool LocationBarView::ShouldShowEVBubble() const { | 1036 bool LocationBarView::ShouldShowEVBubble() const { |
1207 return !chrome::ShouldDisplayOriginChip() && | 1037 return |
1208 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); | 1038 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); |
1209 } | 1039 } |
1210 | 1040 |
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 //////////////////////////////////////////////////////////////////////////////// | 1041 //////////////////////////////////////////////////////////////////////////////// |
1251 // LocationBarView, private LocationBar implementation: | 1042 // LocationBarView, private LocationBar implementation: |
1252 | 1043 |
1253 void LocationBarView::ShowFirstRunBubble() { | 1044 void LocationBarView::ShowFirstRunBubble() { |
1254 // Wait until search engines have loaded to show the first run bubble. | 1045 // Wait until search engines have loaded to show the first run bubble. |
1255 TemplateURLService* url_service = | 1046 TemplateURLService* url_service = |
1256 TemplateURLServiceFactory::GetForProfile(profile()); | 1047 TemplateURLServiceFactory::GetForProfile(profile()); |
1257 if (!url_service->loaded()) { | 1048 if (!url_service->loaded()) { |
1258 template_url_service_ = url_service; | 1049 template_url_service_ = url_service; |
1259 template_url_service_->AddObserver(this); | 1050 template_url_service_->AddObserver(this); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1345 SchedulePaint(); | 1136 SchedulePaint(); |
1346 } | 1137 } |
1347 | 1138 |
1348 void LocationBarView::UpdateGeneratedCreditCardView() { | 1139 void LocationBarView::UpdateGeneratedCreditCardView() { |
1349 generated_credit_card_view_->Update(); | 1140 generated_credit_card_view_->Update(); |
1350 Layout(); | 1141 Layout(); |
1351 SchedulePaint(); | 1142 SchedulePaint(); |
1352 } | 1143 } |
1353 | 1144 |
1354 void LocationBarView::SaveStateToContents(WebContents* contents) { | 1145 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); | 1146 omnibox_view_->SaveStateToTab(contents); |
1361 } | 1147 } |
1362 | 1148 |
1363 const OmniboxView* LocationBarView::GetOmniboxView() const { | 1149 const OmniboxView* LocationBarView::GetOmniboxView() const { |
1364 return omnibox_view_; | 1150 return omnibox_view_; |
1365 } | 1151 } |
1366 | 1152 |
1367 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { | 1153 LocationBarTesting* LocationBarView::GetLocationBarForTesting() { |
1368 return this; | 1154 return this; |
1369 } | 1155 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | 1255 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
1470 } | 1256 } |
1471 | 1257 |
1472 // The border itself will be drawn in PaintChildren() since it includes an | 1258 // The border itself will be drawn in PaintChildren() since it includes an |
1473 // inner shadow which should be drawn over the contents. | 1259 // inner shadow which should be drawn over the contents. |
1474 } | 1260 } |
1475 | 1261 |
1476 void LocationBarView::PaintChildren(gfx::Canvas* canvas, | 1262 void LocationBarView::PaintChildren(gfx::Canvas* canvas, |
1477 const views::CullSet& cull_set) { | 1263 const views::CullSet& cull_set) { |
1478 // Paint all the children except for the omnibox itself, which may need to be | 1264 // 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, | 1265 // clipped if it's animating in, and the search button, which will be painted |
1480 // which will be painted after the border. | 1266 // after the border. |
1481 for (int i = 0, count = child_count(); i < count; ++i) { | 1267 for (int i = 0, count = child_count(); i < count; ++i) { |
1482 views::View* child = child_at(i); | 1268 views::View* child = child_at(i); |
1483 if (!child->layer() && (child != omnibox_view_) && | 1269 if (!child->layer() && (child != omnibox_view_) && |
1484 (child != origin_chip_view_) && (child != search_button_)) | 1270 (child != search_button_)) |
1485 child->Paint(canvas, cull_set); | 1271 child->Paint(canvas, cull_set); |
1486 } | 1272 } |
1487 | 1273 |
1488 { | 1274 { |
1489 gfx::ScopedCanvas scoped_canvas(canvas); | 1275 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); | 1276 omnibox_view_->Paint(canvas, cull_set); |
1499 } | 1277 } |
1500 | 1278 |
1501 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need | 1279 // 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 | 1280 // the focus rect to appear on top of children we paint here rather than |
1503 // OnPaint(). | 1281 // OnPaint(). |
1504 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. | 1282 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. |
1505 if (show_focus_rect_ && HasFocus()) | 1283 if (show_focus_rect_ && HasFocus()) |
1506 canvas->DrawFocusRect(omnibox_view_->bounds()); | 1284 canvas->DrawFocusRect(omnibox_view_->bounds()); |
1507 | 1285 |
1508 // Maximized popup windows don't draw the horizontal edges. We implement this | 1286 // 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. | 1287 // by simply expanding the paint area outside the view by the edge thickness. |
1510 gfx::Rect border_rect(GetContentsBounds()); | 1288 gfx::Rect border_rect(GetContentsBounds()); |
1511 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) | 1289 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) |
1512 border_rect.Inset(-kPopupEdgeThickness, 0); | 1290 border_rect.Inset(-kPopupEdgeThickness, 0); |
1513 views::Painter::PaintPainterAt(canvas, border_painter_.get(), border_rect); | 1291 views::Painter::PaintPainterAt(canvas, border_painter_.get(), border_rect); |
1514 | 1292 |
1515 // The origin chip and the search button must be painted after the border so | 1293 // The search button must be painted after the border so that the border |
1516 // that the border shadow is not drawn over them. | 1294 // shadow is not drawn over them. |
1517 origin_chip_view_->Paint(canvas, cull_set); | |
1518 search_button_->Paint(canvas, cull_set); | 1295 search_button_->Paint(canvas, cull_set); |
1519 } | 1296 } |
1520 | 1297 |
1521 //////////////////////////////////////////////////////////////////////////////// | 1298 //////////////////////////////////////////////////////////////////////////////// |
1522 // LocationBarView, private views::ButtonListener implementation: | 1299 // LocationBarView, private views::ButtonListener implementation: |
1523 | 1300 |
1524 void LocationBarView::ButtonPressed(views::Button* sender, | 1301 void LocationBarView::ButtonPressed(views::Button* sender, |
1525 const ui::Event& event) { | 1302 const ui::Event& event) { |
1526 if (sender == mic_search_view_) { | 1303 if (sender == mic_search_view_) { |
1527 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); | 1304 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); |
(...skipping 22 matching lines...) Expand all Loading... |
1550 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), | 1327 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), |
1551 web_contents->GetTitle(), | 1328 web_contents->GetTitle(), |
1552 favicon, | 1329 favicon, |
1553 NULL, | 1330 NULL, |
1554 data, | 1331 data, |
1555 sender->GetWidget()); | 1332 sender->GetWidget()); |
1556 } | 1333 } |
1557 | 1334 |
1558 int LocationBarView::GetDragOperationsForView(views::View* sender, | 1335 int LocationBarView::GetDragOperationsForView(views::View* sender, |
1559 const gfx::Point& p) { | 1336 const gfx::Point& p) { |
1560 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_) || | 1337 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_)); |
1561 (sender == origin_chip_view_)); | |
1562 WebContents* web_contents = delegate_->GetWebContents(); | 1338 WebContents* web_contents = delegate_->GetWebContents(); |
1563 return (web_contents && web_contents->GetURL().is_valid() && | 1339 return (web_contents && web_contents->GetURL().is_valid() && |
1564 (!GetOmniboxView()->IsEditingOrEmpty() || | 1340 (!GetOmniboxView()->IsEditingOrEmpty())) ? |
1565 sender == origin_chip_view_)) ? | |
1566 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) : | 1341 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) : |
1567 ui::DragDropTypes::DRAG_NONE; | 1342 ui::DragDropTypes::DRAG_NONE; |
1568 } | 1343 } |
1569 | 1344 |
1570 bool LocationBarView::CanStartDragForView(View* sender, | 1345 bool LocationBarView::CanStartDragForView(View* sender, |
1571 const gfx::Point& press_pt, | 1346 const gfx::Point& press_pt, |
1572 const gfx::Point& p) { | 1347 const gfx::Point& p) { |
1573 return true; | 1348 return true; |
1574 } | 1349 } |
1575 | 1350 |
(...skipping 10 matching lines...) Expand all Loading... |
1586 chrome::GetDisplaySearchButtonConditions(); | 1361 chrome::GetDisplaySearchButtonConditions(); |
1587 bool meets_conditions = | 1362 bool meets_conditions = |
1588 (conditions == chrome::DISPLAY_SEARCH_BUTTON_ALWAYS) || | 1363 (conditions == chrome::DISPLAY_SEARCH_BUTTON_ALWAYS) || |
1589 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) && | 1364 ((conditions != chrome::DISPLAY_SEARCH_BUTTON_NEVER) && |
1590 (toolbar_model->WouldPerformSearchTermReplacement(true) || | 1365 (toolbar_model->WouldPerformSearchTermReplacement(true) || |
1591 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && | 1366 ((conditions == chrome::DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP) && |
1592 toolbar_model->input_in_progress()))); | 1367 toolbar_model->input_in_progress()))); |
1593 search_button_->SetVisible(!is_popup_mode_ && meets_conditions); | 1368 search_button_->SetVisible(!is_popup_mode_ && meets_conditions); |
1594 search_button_->UpdateIcon(icon_id == IDR_OMNIBOX_SEARCH); | 1369 search_button_->UpdateIcon(icon_id == IDR_OMNIBOX_SEARCH); |
1595 | 1370 |
1596 origin_chip_view_->OnChanged(); | |
1597 | |
1598 Layout(); | 1371 Layout(); |
1599 SchedulePaint(); | 1372 SchedulePaint(); |
1600 } | 1373 } |
1601 | 1374 |
1602 void LocationBarView::OnSetFocus() { | 1375 void LocationBarView::OnSetFocus() { |
1603 GetFocusManager()->SetFocusedView(this); | 1376 GetFocusManager()->SetFocusedView(this); |
1604 } | 1377 } |
1605 | 1378 |
1606 InstantController* LocationBarView::GetInstant() { | 1379 InstantController* LocationBarView::GetInstant() { |
1607 return delegate_->GetInstant(); | 1380 return delegate_->GetInstant(); |
1608 } | 1381 } |
1609 | 1382 |
1610 const ToolbarModel* LocationBarView::GetToolbarModel() const { | 1383 const ToolbarModel* LocationBarView::GetToolbarModel() const { |
1611 return delegate_->GetToolbarModel(); | 1384 return delegate_->GetToolbarModel(); |
1612 } | 1385 } |
1613 | 1386 |
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 //////////////////////////////////////////////////////////////////////////////// | 1387 //////////////////////////////////////////////////////////////////////////////// |
1632 // LocationBarView, private DropdownBarHostDelegate implementation: | 1388 // LocationBarView, private DropdownBarHostDelegate implementation: |
1633 | 1389 |
1634 void LocationBarView::SetFocusAndSelection(bool select_all) { | 1390 void LocationBarView::SetFocusAndSelection(bool select_all) { |
1635 FocusLocation(select_all); | 1391 FocusLocation(select_all); |
1636 } | 1392 } |
1637 | 1393 |
1638 void LocationBarView::SetAnimationOffset(int offset) { | 1394 void LocationBarView::SetAnimationOffset(int offset) { |
1639 dropdown_animation_offset_ = offset; | 1395 dropdown_animation_offset_ = offset; |
1640 } | 1396 } |
1641 | 1397 |
1642 //////////////////////////////////////////////////////////////////////////////// | 1398 //////////////////////////////////////////////////////////////////////////////// |
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: | 1399 // LocationBarView, private TemplateURLServiceObserver implementation: |
1667 | 1400 |
1668 void LocationBarView::OnTemplateURLServiceChanged() { | 1401 void LocationBarView::OnTemplateURLServiceChanged() { |
1669 template_url_service_->RemoveObserver(this); | 1402 template_url_service_->RemoveObserver(this); |
1670 template_url_service_ = NULL; | 1403 template_url_service_ = NULL; |
1671 // If the browser is no longer active, let's not show the info bubble, as this | 1404 // 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. | 1405 // would make the browser the active window again. |
1673 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1406 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
1674 ShowFirstRunBubble(); | 1407 ShowFirstRunBubble(); |
1675 } | 1408 } |
1676 | 1409 |
1677 //////////////////////////////////////////////////////////////////////////////// | 1410 //////////////////////////////////////////////////////////////////////////////// |
1678 // LocationBarView, private SearchModelObserver implementation: | 1411 // LocationBarView, private SearchModelObserver implementation: |
1679 | 1412 |
1680 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1413 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
1681 const SearchModel::State& new_state) { | 1414 const SearchModel::State& new_state) { |
1682 const bool visible = !GetToolbarModel()->input_in_progress() && | 1415 const bool visible = !GetToolbarModel()->input_in_progress() && |
1683 new_state.voice_search_supported; | 1416 new_state.voice_search_supported; |
1684 if (mic_search_view_->visible() != visible) { | 1417 if (mic_search_view_->visible() != visible) { |
1685 mic_search_view_->SetVisible(visible); | 1418 mic_search_view_->SetVisible(visible); |
1686 Layout(); | 1419 Layout(); |
1687 } | 1420 } |
1688 } | 1421 } |
OLD | NEW |