OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 Delegate* delegate, | 205 Delegate* delegate, |
206 bool is_popup_mode) | 206 bool is_popup_mode) |
207 : LocationBar(profile), | 207 : LocationBar(profile), |
208 OmniboxEditController(command_updater), | 208 OmniboxEditController(command_updater), |
209 browser_(browser), | 209 browser_(browser), |
210 omnibox_view_(NULL), | 210 omnibox_view_(NULL), |
211 delegate_(delegate), | 211 delegate_(delegate), |
212 origin_chip_view_(NULL), | 212 origin_chip_view_(NULL), |
213 location_icon_view_(NULL), | 213 location_icon_view_(NULL), |
214 ev_bubble_view_(NULL), | 214 ev_bubble_view_(NULL), |
| 215 good_bubble_view_(NULL), |
| 216 dubious_bubble_view_(NULL), |
| 217 bad_bubble_view_(NULL), |
215 ime_inline_autocomplete_view_(NULL), | 218 ime_inline_autocomplete_view_(NULL), |
216 selected_keyword_view_(NULL), | 219 selected_keyword_view_(NULL), |
217 suggested_text_view_(NULL), | 220 suggested_text_view_(NULL), |
218 keyword_hint_view_(NULL), | 221 keyword_hint_view_(NULL), |
219 mic_search_view_(NULL), | 222 mic_search_view_(NULL), |
220 zoom_view_(NULL), | 223 zoom_view_(NULL), |
221 generated_credit_card_view_(NULL), | 224 generated_credit_card_view_(NULL), |
222 open_pdf_in_reader_view_(NULL), | 225 open_pdf_in_reader_view_(NULL), |
223 manage_passwords_icon_view_(NULL), | 226 manage_passwords_icon_view_(NULL), |
224 translate_icon_view_(NULL), | 227 translate_icon_view_(NULL), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // images have 1 px thick edges, which we don't want to overlap. | 290 // images have 1 px thick edges, which we don't want to overlap. |
288 const int kBubbleInteriorVerticalPadding = 1; | 291 const int kBubbleInteriorVerticalPadding = 1; |
289 const int bubble_vertical_padding = | 292 const int bubble_vertical_padding = |
290 (kBubblePadding + kBubbleInteriorVerticalPadding) * 2; | 293 (kBubblePadding + kBubbleInteriorVerticalPadding) * 2; |
291 const gfx::FontList bubble_font_list( | 294 const gfx::FontList bubble_font_list( |
292 GetLargestFontListWithHeightBound( | 295 GetLargestFontListWithHeightBound( |
293 font_list, location_height - bubble_vertical_padding)); | 296 font_list, location_height - bubble_vertical_padding)); |
294 | 297 |
295 const SkColor background_color = | 298 const SkColor background_color = |
296 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND); | 299 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND); |
| 300 |
297 ev_bubble_view_ = new EVBubbleView( | 301 ev_bubble_view_ = new EVBubbleView( |
298 bubble_font_list, GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), | 302 bubble_font_list, GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), |
299 background_color, this); | 303 background_color, this); |
300 ev_bubble_view_->set_drag_controller(this); | 304 ev_bubble_view_->set_drag_controller(this); |
301 AddChildView(ev_bubble_view_); | 305 AddChildView(ev_bubble_view_); |
302 | 306 |
| 307 good_bubble_view_ = new EVBubbleView( |
| 308 bubble_font_list, GetColor(ToolbarModel::SECURE, SECURITY_TEXT), |
| 309 background_color, this); |
| 310 good_bubble_view_->set_drag_controller(this); |
| 311 AddChildView(good_bubble_view_); |
| 312 |
| 313 dubious_bubble_view_ = new EVBubbleView( |
| 314 bubble_font_list, GetColor(ToolbarModel::SECURITY_WARNING, SECURITY_TEXT), |
| 315 background_color, this); |
| 316 dubious_bubble_view_->set_drag_controller(this); |
| 317 AddChildView(dubious_bubble_view_); |
| 318 |
| 319 bad_bubble_view_ = new EVBubbleView( |
| 320 bubble_font_list, GetColor(ToolbarModel::SECURITY_ERROR, SECURITY_TEXT), |
| 321 background_color, this); |
| 322 bad_bubble_view_->set_drag_controller(this); |
| 323 AddChildView(bad_bubble_view_); |
| 324 |
303 // Initialize the Omnibox view. | 325 // Initialize the Omnibox view. |
304 omnibox_view_ = new OmniboxViewViews( | 326 omnibox_view_ = new OmniboxViewViews( |
305 this, profile(), command_updater(), | 327 this, profile(), command_updater(), |
306 is_popup_mode_ || | 328 is_popup_mode_ || |
307 (browser_->is_app() && CommandLine::ForCurrentProcess()-> | 329 (browser_->is_app() && CommandLine::ForCurrentProcess()-> |
308 HasSwitch(switches::kEnableStreamlinedHostedApps)), | 330 HasSwitch(switches::kEnableStreamlinedHostedApps)), |
309 this, font_list); | 331 this, font_list); |
310 omnibox_view_->Init(); | 332 omnibox_view_->Init(); |
311 omnibox_view_->SetFocusable(true); | 333 omnibox_view_->SetFocusable(true); |
312 AddChildView(omnibox_view_); | 334 AddChildView(omnibox_view_); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 } | 712 } |
691 | 713 |
692 void LocationBarView::Layout() { | 714 void LocationBarView::Layout() { |
693 if (!IsInitialized()) | 715 if (!IsInitialized()) |
694 return; | 716 return; |
695 | 717 |
696 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip()); | 718 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip()); |
697 selected_keyword_view_->SetVisible(false); | 719 selected_keyword_view_->SetVisible(false); |
698 location_icon_view_->SetVisible(false); | 720 location_icon_view_->SetVisible(false); |
699 ev_bubble_view_->SetVisible(false); | 721 ev_bubble_view_->SetVisible(false); |
| 722 good_bubble_view_->SetVisible(false); |
| 723 dubious_bubble_view_->SetVisible(false); |
| 724 bad_bubble_view_->SetVisible(false); |
700 keyword_hint_view_->SetVisible(false); | 725 keyword_hint_view_->SetVisible(false); |
701 | 726 |
702 LocationBarLayout leading_decorations( | 727 LocationBarLayout leading_decorations( |
703 LocationBarLayout::LEFT_EDGE, | 728 LocationBarLayout::LEFT_EDGE, |
704 kItemPadding - GetEditLeadingInternalSpace()); | 729 kItemPadding - GetEditLeadingInternalSpace()); |
705 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE, | 730 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE, |
706 kItemPadding); | 731 kItemPadding); |
707 | 732 |
708 const int origin_chip_preferred_width = | 733 const int origin_chip_preferred_width = |
709 origin_chip_view_->GetPreferredSize().width(); | 734 origin_chip_view_->GetPreferredSize().width(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 selected_keyword_view_->set_is_extension_icon(false); | 769 selected_keyword_view_->set_is_extension_icon(false); |
745 } | 770 } |
746 } | 771 } |
747 } else if (ShouldShowEVBubble()) { | 772 } else if (ShouldShowEVBubble()) { |
748 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); | 773 ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); |
749 // The largest fraction of the omnibox that can be taken by the EV bubble. | 774 // The largest fraction of the omnibox that can be taken by the EV bubble. |
750 const double kMaxBubbleFraction = 0.5; | 775 const double kMaxBubbleFraction = 0.5; |
751 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, | 776 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, |
752 kMaxBubbleFraction, kBubblePadding, | 777 kMaxBubbleFraction, kBubblePadding, |
753 kItemPadding, ev_bubble_view_); | 778 kItemPadding, ev_bubble_view_); |
| 779 } else if (ShouldShowGoodBubble()) { |
| 780 good_bubble_view_->SetLabel(GetToolbarModel()->GetOriginDisplayName()); |
| 781 // The largest fraction of the omnibox that can be taken by the Good bubble. |
| 782 const double kMaxBubbleFraction = 0.5; |
| 783 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, |
| 784 kMaxBubbleFraction, kBubblePadding, |
| 785 kItemPadding, good_bubble_view_); |
| 786 } else if (ShouldShowDubiousBubble()) { |
| 787 dubious_bubble_view_->SetLabel(GetToolbarModel()->GetOriginDisplayName()); |
| 788 // The largest fraction of the omnibox that can be taken by the Dubious |
| 789 // bubble. |
| 790 const double kMaxBubbleFraction = 0.5; |
| 791 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, |
| 792 kMaxBubbleFraction, kBubblePadding, |
| 793 kItemPadding, dubious_bubble_view_); |
| 794 } else if (ShouldShowBadBubble()) { |
| 795 bad_bubble_view_->SetLabel(GetToolbarModel()->GetOriginDisplayName()); |
| 796 // The largest fraction of the omnibox that can be taken by the Bad bubble. |
| 797 const double kMaxBubbleFraction = 0.5; |
| 798 leading_decorations.AddDecoration(bubble_location_y, bubble_height, false, |
| 799 kMaxBubbleFraction, kBubblePadding, |
| 800 kItemPadding, bad_bubble_view_); |
754 } else if (!origin_chip_view_->visible()) { | 801 } else if (!origin_chip_view_->visible()) { |
755 leading_decorations.AddDecoration( | 802 leading_decorations.AddDecoration( |
756 vertical_edge_thickness(), location_height, | 803 vertical_edge_thickness(), location_height, |
757 location_icon_view_); | 804 location_icon_view_); |
758 } | 805 } |
759 | 806 |
760 if (star_view_->visible()) { | 807 if (star_view_->visible()) { |
761 trailing_decorations.AddDecoration( | 808 trailing_decorations.AddDecoration( |
762 vertical_edge_thickness(), location_height, star_view_); | 809 vertical_edge_thickness(), location_height, star_view_); |
763 } | 810 } |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 bool LocationBarView::ShouldShowKeywordBubble() const { | 1328 bool LocationBarView::ShouldShowKeywordBubble() const { |
1282 return !omnibox_view_->model()->keyword().empty() && | 1329 return !omnibox_view_->model()->keyword().empty() && |
1283 !omnibox_view_->model()->is_keyword_hint(); | 1330 !omnibox_view_->model()->is_keyword_hint(); |
1284 } | 1331 } |
1285 | 1332 |
1286 bool LocationBarView::ShouldShowEVBubble() const { | 1333 bool LocationBarView::ShouldShowEVBubble() const { |
1287 return !chrome::ShouldDisplayOriginChip() && | 1334 return !chrome::ShouldDisplayOriginChip() && |
1288 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); | 1335 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); |
1289 } | 1336 } |
1290 | 1337 |
| 1338 bool LocationBarView::ShouldShowGoodBubble() const { |
| 1339 return !chrome::ShouldDisplayOriginChip() && |
| 1340 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::SECURE); |
| 1341 } |
| 1342 |
| 1343 bool LocationBarView::ShouldShowDubiousBubble() const { |
| 1344 ToolbarModel::SecurityLevel security = |
| 1345 GetToolbarModel()->GetSecurityLevel(false); |
| 1346 return !chrome::ShouldDisplayOriginChip() && |
| 1347 (security == ToolbarModel::SECURITY_POLICY_WARNING || |
| 1348 security == ToolbarModel::SECURITY_WARNING); |
| 1349 } |
| 1350 |
| 1351 bool LocationBarView::ShouldShowBadBubble() const { |
| 1352 ToolbarModel::SecurityLevel security = |
| 1353 GetToolbarModel()->GetSecurityLevel(false); |
| 1354 return !chrome::ShouldDisplayOriginChip() && |
| 1355 (security == ToolbarModel::NONE || |
| 1356 security == ToolbarModel::SECURITY_ERROR); |
| 1357 } |
| 1358 |
1291 double LocationBarView::GetValueForAnimation(bool hide) const { | 1359 double LocationBarView::GetValueForAnimation(bool hide) const { |
1292 int calculated_offset; | 1360 int calculated_offset; |
1293 const gfx::Tween::Type tween_type = hide ? kHideTweenType : kShowTweenType; | 1361 const gfx::Tween::Type tween_type = hide ? kHideTweenType : kShowTweenType; |
1294 int start_offset = starting_omnibox_offset_, end_offset = 0; | 1362 int start_offset = starting_omnibox_offset_, end_offset = 0; |
1295 if (hide) | 1363 if (hide) |
1296 std::swap(start_offset, end_offset); | 1364 std::swap(start_offset, end_offset); |
1297 const int desired_offset = abs(current_omnibox_offset_); | 1365 const int desired_offset = abs(current_omnibox_offset_); |
1298 // Binary-search the value space (0 <= value <= 1) to find the appropriate | 1366 // Binary-search the value space (0 <= value <= 1) to find the appropriate |
1299 // position. We only bother to iterate to within 1/64 of the desired value, | 1367 // position. We only bother to iterate to within 1/64 of the desired value, |
1300 // because the longer of the two animations will only run for twelve frames | 1368 // because the longer of the two animations will only run for twelve frames |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1763 | 1831 |
1764 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1832 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
1765 const SearchModel::State& new_state) { | 1833 const SearchModel::State& new_state) { |
1766 const bool visible = !GetToolbarModel()->input_in_progress() && | 1834 const bool visible = !GetToolbarModel()->input_in_progress() && |
1767 new_state.voice_search_supported; | 1835 new_state.voice_search_supported; |
1768 if (mic_search_view_->visible() != visible) { | 1836 if (mic_search_view_->visible() != visible) { |
1769 mic_search_view_->SetVisible(visible); | 1837 mic_search_view_->SetVisible(visible); |
1770 Layout(); | 1838 Layout(); |
1771 } | 1839 } |
1772 } | 1840 } |
OLD | NEW |