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/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" | 41 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.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/keyword_hint_view.h" | 44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
45 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 45 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
46 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 46 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
47 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 47 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
48 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 48 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
49 #include "chrome/browser/ui/views/location_bar/star_view.h" | 49 #include "chrome/browser/ui/views/location_bar/star_view.h" |
50 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" | 50 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" |
51 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | |
52 #include "chrome/browser/ui/views/location_bar/zoom_view.h" | |
51 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 53 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
52 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" | 54 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" |
53 #include "chrome/browser/ui/webui/instant_ui.h" | 55 #include "chrome/browser/ui/webui/instant_ui.h" |
54 #include "chrome/common/chrome_notification_types.h" | 56 #include "chrome/common/chrome_notification_types.h" |
55 #include "chrome/common/chrome_switches.h" | 57 #include "chrome/common/chrome_switches.h" |
56 #include "chrome/common/extensions/extension_switch_utils.h" | 58 #include "chrome/common/extensions/extension_switch_utils.h" |
57 #include "chrome/common/pref_names.h" | 59 #include "chrome/common/pref_names.h" |
58 #include "content/public/browser/notification_service.h" | 60 #include "content/public/browser/notification_service.h" |
59 #include "content/public/browser/render_widget_host_view.h" | 61 #include "content/public/browser/render_widget_host_view.h" |
60 #include "content/public/browser/web_contents.h" | 62 #include "content/public/browser/web_contents.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 disposition_(CURRENT_TAB), | 173 disposition_(CURRENT_TAB), |
172 transition_(content::PageTransitionFromInt( | 174 transition_(content::PageTransitionFromInt( |
173 content::PAGE_TRANSITION_TYPED | | 175 content::PAGE_TRANSITION_TYPED | |
174 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), | 176 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
175 location_icon_view_(NULL), | 177 location_icon_view_(NULL), |
176 ev_bubble_view_(NULL), | 178 ev_bubble_view_(NULL), |
177 location_entry_view_(NULL), | 179 location_entry_view_(NULL), |
178 selected_keyword_view_(NULL), | 180 selected_keyword_view_(NULL), |
179 suggested_text_view_(NULL), | 181 suggested_text_view_(NULL), |
180 keyword_hint_view_(NULL), | 182 keyword_hint_view_(NULL), |
183 zoom_view_(NULL), | |
181 star_view_(NULL), | 184 star_view_(NULL), |
182 action_box_button_view_(NULL), | 185 action_box_button_view_(NULL), |
183 chrome_to_mobile_view_(NULL), | 186 chrome_to_mobile_view_(NULL), |
184 mode_(mode), | 187 mode_(mode), |
185 show_focus_rect_(false), | 188 show_focus_rect_(false), |
186 template_url_service_(NULL), | 189 template_url_service_(NULL), |
187 animation_offset_(0), | 190 animation_offset_(0), |
188 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) { | 191 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) { |
189 set_id(VIEW_ID_LOCATION_BAR); | 192 set_id(VIEW_ID_LOCATION_BAR); |
190 | 193 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 keyword_hint_view_->SetFont(font_); | 264 keyword_hint_view_->SetFont(font_); |
262 | 265 |
263 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 266 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
264 ContentSettingImageView* content_blocked_view = | 267 ContentSettingImageView* content_blocked_view = |
265 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this); | 268 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this); |
266 content_setting_views_.push_back(content_blocked_view); | 269 content_setting_views_.push_back(content_blocked_view); |
267 AddChildView(content_blocked_view); | 270 AddChildView(content_blocked_view); |
268 content_blocked_view->SetVisible(false); | 271 content_blocked_view->SetVisible(false); |
269 } | 272 } |
270 | 273 |
274 zoom_view_ = new ZoomView(model_); | |
275 AddChildView(zoom_view_); | |
276 | |
271 if (extensions::switch_utils::IsActionBoxEnabled()) { | 277 if (extensions::switch_utils::IsActionBoxEnabled()) { |
272 action_box_button_view_ = new ActionBoxButtonView( | 278 action_box_button_view_ = new ActionBoxButtonView( |
273 ExtensionSystem::Get(profile_)->extension_service()); | 279 ExtensionSystem::Get(profile_)->extension_service()); |
274 AddChildView(action_box_button_view_); | 280 AddChildView(action_box_button_view_); |
275 } else if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { | 281 } else if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { |
276 // Note: condition above means that the star and ChromeToMobile icons are | 282 // Note: condition above means that the star and ChromeToMobile icons are |
277 // hidden in popups and in the app launcher. | 283 // hidden in popups and in the app launcher. |
278 star_view_ = new StarView(command_updater_); | 284 star_view_ = new StarView(command_updater_); |
279 AddChildView(star_view_); | 285 AddChildView(star_view_); |
280 star_view_->SetVisible(true); | 286 star_view_->SetVisible(true); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 // Fade in so the icons don't pop. | 389 // Fade in so the icons don't pop. |
384 StartFadeAnimation(); | 390 StartFadeAnimation(); |
385 } else { | 391 } else { |
386 // Cancel any pending animations; switch to the final state immediately. | 392 // Cancel any pending animations; switch to the final state immediately. |
387 StopFadeAnimation(); | 393 StopFadeAnimation(); |
388 } | 394 } |
389 #endif | 395 #endif |
390 } | 396 } |
391 | 397 |
392 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { | 398 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { |
399 RefreshContentSettingViews(); | |
400 zoom_view_->Update(); | |
401 RefreshPageActionViews(); | |
402 | |
393 bool star_enabled = star_view_ && !model_->input_in_progress() && | 403 bool star_enabled = star_view_ && !model_->input_in_progress() && |
394 edit_bookmarks_enabled_.GetValue(); | 404 edit_bookmarks_enabled_.GetValue(); |
395 | 405 |
396 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); | 406 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); |
397 if (star_view_) | 407 if (star_view_) |
398 star_view_->SetVisible(star_enabled); | 408 star_view_->SetVisible(star_enabled); |
399 | 409 |
400 bool enabled = chrome_to_mobile_view_ && !model_->input_in_progress() && | 410 bool enabled = chrome_to_mobile_view_ && !model_->input_in_progress() && |
401 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasDevices(); | 411 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasDevices(); |
402 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); | 412 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); |
403 | 413 |
404 RefreshContentSettingViews(); | |
405 RefreshPageActionViews(); | |
406 // Don't Update in app launcher mode so that the location entry does not show | 414 // Don't Update in app launcher mode so that the location entry does not show |
407 // a URL or security background. | 415 // a URL or security background. |
408 if (mode_ != APP_LAUNCHER) | 416 if (mode_ != APP_LAUNCHER) |
409 location_entry_->Update(tab_for_state_restoring); | 417 location_entry_->Update(tab_for_state_restoring); |
410 OnChanged(); | 418 OnChanged(); |
411 } | 419 } |
412 | 420 |
413 void LocationBarView::UpdateContentSettingsIcons() { | 421 void LocationBarView::UpdateContentSettingsIcons() { |
414 RefreshContentSettingViews(); | 422 RefreshContentSettingViews(); |
415 | 423 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 | 496 |
489 void LocationBarView::SetStarToggled(bool on) { | 497 void LocationBarView::SetStarToggled(bool on) { |
490 if (star_view_) | 498 if (star_view_) |
491 star_view_->SetToggled(on); | 499 star_view_->SetToggled(on); |
492 } | 500 } |
493 | 501 |
494 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { | 502 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { |
495 browser::ShowBookmarkBubbleView(star_view_, profile_, url, newly_bookmarked); | 503 browser::ShowBookmarkBubbleView(star_view_, profile_, url, newly_bookmarked); |
496 } | 504 } |
497 | 505 |
506 void LocationBarView::SetZoomIconTooltipPercent(int zoom_percent) { | |
507 zoom_view_->SetZoomIconTooltipPercent(zoom_percent); | |
508 } | |
509 | |
510 void LocationBarView::SetZoomIconState( | |
511 ZoomController::ZoomIconState zoom_icon_state) { | |
512 zoom_view_->SetZoomIconState(zoom_icon_state); | |
513 } | |
514 | |
515 void LocationBarView::ShowZoomBubble(int zoom_percent) { | |
516 ZoomBubbleView::ShowBubble(zoom_view_, zoom_percent, true); | |
517 } | |
518 | |
498 void LocationBarView::ShowChromeToMobileBubble() { | 519 void LocationBarView::ShowChromeToMobileBubble() { |
499 Browser* browser = GetBrowserFromDelegate(delegate_); | 520 Browser* browser = GetBrowserFromDelegate(delegate_); |
500 browser::ShowChromeToMobileBubbleView(chrome_to_mobile_view_, browser); | 521 browser::ShowChromeToMobileBubbleView(chrome_to_mobile_view_, browser); |
501 } | 522 } |
502 | 523 |
503 gfx::Point LocationBarView::GetLocationEntryOrigin() const { | 524 gfx::Point LocationBarView::GetLocationEntryOrigin() const { |
504 gfx::Point origin(location_entry_view_->bounds().origin()); | 525 gfx::Point origin(location_entry_view_->bounds().origin()); |
505 // If the UI layout is RTL, the coordinate system is not transformed and | 526 // If the UI layout is RTL, the coordinate system is not transformed and |
506 // therefore we need to adjust the X coordinate so that bubble appears on the | 527 // therefore we need to adjust the X coordinate so that bubble appears on the |
507 // right hand side of the location bar. | 528 // right hand side of the location bar. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 // We'll adjust this width and take it out of |entry_width| below. | 647 // We'll adjust this width and take it out of |entry_width| below. |
627 } else { | 648 } else { |
628 location_icon_view_->SetVisible(true); | 649 location_icon_view_->SetVisible(true); |
629 location_icon_width = location_icon_view_->GetPreferredSize().width(); | 650 location_icon_width = location_icon_view_->GetPreferredSize().width(); |
630 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + | 651 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + |
631 location_icon_width + kItemEditPadding); | 652 location_icon_width + kItemEditPadding); |
632 } | 653 } |
633 | 654 |
634 if (star_view_ && star_view_->visible()) | 655 if (star_view_ && star_view_->visible()) |
635 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); | 656 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); |
636 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) | 657 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { |
637 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + | 658 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + |
638 GetItemPadding(); | 659 GetItemPadding(); |
660 } | |
639 int action_box_button_width = location_height; | 661 int action_box_button_width = location_height; |
640 if (action_box_button_view_) | 662 if (action_box_button_view_) |
641 entry_width -= action_box_button_width + GetItemPadding(); | 663 entry_width -= action_box_button_width + GetItemPadding(); |
642 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 664 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
643 i != page_action_views_.end(); ++i) { | 665 i != page_action_views_.end(); ++i) { |
644 if ((*i)->visible()) | 666 if ((*i)->visible()) |
645 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); | 667 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); |
646 } | 668 } |
669 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding(); | |
Peter Kasting
2012/07/02 19:21:27
This should only happen if the zoom icon is visibl
Kyle Horimoto
2012/07/02 21:09:02
Done.
| |
647 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 670 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
648 i != content_setting_views_.end(); ++i) { | 671 i != content_setting_views_.end(); ++i) { |
649 if ((*i)->visible()) | 672 if ((*i)->visible()) |
650 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); | 673 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); |
651 } | 674 } |
652 // The gap between the edit and whatever is to its right is shortened. | 675 // The gap between the edit and whatever is to its right is shortened. |
653 entry_width += kEditInternalSpace; | 676 entry_width += kEditInternalSpace; |
654 | 677 |
655 // Size the EV bubble after taking star/ChromeToMobile/page actions/content | 678 // Size the EV bubble after taking star/ChromeToMobile/page actions/content |
656 // settings out of |entry_width| so we won't take too much space. | 679 // settings out of |entry_width| so we won't take too much space. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
731 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 754 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
732 i != page_action_views_.end(); ++i) { | 755 i != page_action_views_.end(); ++i) { |
733 if ((*i)->visible()) { | 756 if ((*i)->visible()) { |
734 offset += (*i)->GetBuiltInHorizontalPadding(); | 757 offset += (*i)->GetBuiltInHorizontalPadding(); |
735 int page_action_width = (*i)->GetPreferredSize().width(); | 758 int page_action_width = (*i)->GetPreferredSize().width(); |
736 offset -= page_action_width; | 759 offset -= page_action_width; |
737 (*i)->SetBounds(offset, location_y, page_action_width, location_height); | 760 (*i)->SetBounds(offset, location_y, page_action_width, location_height); |
738 offset -= GetItemPadding() - (*i)->GetBuiltInHorizontalPadding(); | 761 offset -= GetItemPadding() - (*i)->GetBuiltInHorizontalPadding(); |
739 } | 762 } |
740 } | 763 } |
764 | |
765 int zoom_width = zoom_view_->GetPreferredSize().width(); | |
Peter Kasting
2012/07/02 19:21:27
This block should only happen if the zoom icon is
Kyle Horimoto
2012/07/02 21:09:02
Done.
| |
766 offset -= zoom_width; | |
767 zoom_view_->SetBounds(offset, location_y, zoom_width, location_height); | |
768 offset -= GetItemPadding(); | |
769 | |
741 // We use a reverse_iterator here because we're laying out the views from | 770 // We use a reverse_iterator here because we're laying out the views from |
742 // right to left but in the vector they're ordered left to right. | 771 // right to left but in the vector they're ordered left to right. |
743 for (ContentSettingViews::const_reverse_iterator | 772 for (ContentSettingViews::const_reverse_iterator |
744 i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); | 773 i(content_setting_views_.rbegin()); i != content_setting_views_.rend(); |
745 ++i) { | 774 ++i) { |
746 if ((*i)->visible()) { | 775 if ((*i)->visible()) { |
747 offset += (*i)->GetBuiltInHorizontalPadding(); | 776 offset += (*i)->GetBuiltInHorizontalPadding(); |
748 int content_blocked_width = (*i)->GetPreferredSize().width(); | 777 int content_blocked_width = (*i)->GetPreferredSize().width(); |
749 offset -= content_blocked_width; | 778 offset -= content_blocked_width; |
750 (*i)->SetBounds(offset, location_y, content_blocked_width, | 779 (*i)->SetBounds(offset, location_y, content_blocked_width, |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1457 } | 1486 } |
1458 | 1487 |
1459 void LocationBarView::CleanupFadeAnimation() { | 1488 void LocationBarView::CleanupFadeAnimation() { |
1460 // Since we're no longer animating we don't need our layer. | 1489 // Since we're no longer animating we don't need our layer. |
1461 SetPaintToLayer(false); | 1490 SetPaintToLayer(false); |
1462 // Bubble labels don't need a transparent background anymore. | 1491 // Bubble labels don't need a transparent background anymore. |
1463 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1492 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
1464 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1493 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
1465 } | 1494 } |
1466 #endif // USE_AURA | 1495 #endif // USE_AURA |
OLD | NEW |