Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 35 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" | 35 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" |
| 36 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" | 36 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" |
| 37 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" | 37 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
| 38 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" | 38 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
| 39 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 39 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 40 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 40 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 41 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 41 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 42 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 42 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
| 43 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 43 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
| 44 #include "chrome/browser/ui/views/location_bar/star_view.h" | 44 #include "chrome/browser/ui/views/location_bar/star_view.h" |
| 45 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | |
| 46 #include "chrome/browser/ui/views/location_bar/zoom_view.h" | |
| 45 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 47 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
| 46 #include "chrome/common/chrome_notification_types.h" | 48 #include "chrome/common/chrome_notification_types.h" |
| 47 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
| 48 #include "chrome/common/extensions/extension_switch_utils.h" | 50 #include "chrome/common/extensions/extension_switch_utils.h" |
| 49 #include "chrome/common/pref_names.h" | 51 #include "chrome/common/pref_names.h" |
| 50 #include "content/public/browser/notification_service.h" | 52 #include "content/public/browser/notification_service.h" |
| 51 #include "content/public/browser/render_widget_host_view.h" | 53 #include "content/public/browser/render_widget_host_view.h" |
| 52 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
| 53 #include "grit/generated_resources.h" | 55 #include "grit/generated_resources.h" |
| 54 #include "grit/theme_resources.h" | 56 #include "grit/theme_resources.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), | 143 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
| 142 location_icon_view_(NULL), | 144 location_icon_view_(NULL), |
| 143 ev_bubble_view_(NULL), | 145 ev_bubble_view_(NULL), |
| 144 location_entry_view_(NULL), | 146 location_entry_view_(NULL), |
| 145 selected_keyword_view_(NULL), | 147 selected_keyword_view_(NULL), |
| 146 #if defined(OS_WIN) || defined(USE_AURA) | 148 #if defined(OS_WIN) || defined(USE_AURA) |
| 147 suggested_text_view_(NULL), | 149 suggested_text_view_(NULL), |
| 148 #endif | 150 #endif |
| 149 keyword_hint_view_(NULL), | 151 keyword_hint_view_(NULL), |
| 150 star_view_(NULL), | 152 star_view_(NULL), |
| 153 zoom_view_(NULL), | |
| 151 action_box_button_view_(NULL), | 154 action_box_button_view_(NULL), |
| 152 chrome_to_mobile_view_(NULL), | 155 chrome_to_mobile_view_(NULL), |
| 153 mode_(mode), | 156 mode_(mode), |
| 154 show_focus_rect_(false), | 157 show_focus_rect_(false), |
| 155 template_url_service_(NULL), | 158 template_url_service_(NULL), |
| 156 animation_offset_(0) { | 159 animation_offset_(0) { |
| 157 set_id(VIEW_ID_LOCATION_BAR); | 160 set_id(VIEW_ID_LOCATION_BAR); |
| 158 | 161 |
| 159 if (mode_ == NORMAL) { | 162 if (mode_ == NORMAL) { |
| 160 painter_.reset( | 163 painter_.reset( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 action_box_button_view_ = new ActionBoxButtonView( | 242 action_box_button_view_ = new ActionBoxButtonView( |
| 240 ExtensionSystem::Get(profile_)->extension_service()); | 243 ExtensionSystem::Get(profile_)->extension_service()); |
| 241 AddChildView(action_box_button_view_); | 244 AddChildView(action_box_button_view_); |
| 242 } else if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { | 245 } else if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { |
| 243 // Note: condition above means that the star and ChromeToMobile icons are | 246 // Note: condition above means that the star and ChromeToMobile icons are |
| 244 // hidden in popups and in the app launcher. | 247 // hidden in popups and in the app launcher. |
| 245 star_view_ = new StarView(command_updater_); | 248 star_view_ = new StarView(command_updater_); |
| 246 AddChildView(star_view_); | 249 AddChildView(star_view_); |
| 247 star_view_->SetVisible(true); | 250 star_view_->SetVisible(true); |
| 248 | 251 |
| 252 zoom_view_ = new ZoomView(); | |
|
Peter Kasting
2012/06/22 20:16:20
This should appear in the same cases as the conten
Kyle Horimoto
2012/06/26 21:55:53
Done. Moved below the code adding the Star, etc. i
| |
| 253 AddChildView(zoom_view_); | |
| 254 | |
| 249 // Also disable Chrome To Mobile for off-the-record and non-synced profiles, | 255 // Also disable Chrome To Mobile for off-the-record and non-synced profiles, |
| 250 // or if the feature is disabled by a command line flag or chrome://flags. | 256 // or if the feature is disabled by a command line flag or chrome://flags. |
| 251 if (!profile_->IsOffTheRecord() && profile_->IsSyncAccessible() && | 257 if (!profile_->IsOffTheRecord() && profile_->IsSyncAccessible() && |
| 252 ChromeToMobileService::IsChromeToMobileEnabled()) { | 258 ChromeToMobileService::IsChromeToMobileEnabled()) { |
| 253 chrome_to_mobile_view_ = new ChromeToMobileView(this, command_updater_); | 259 chrome_to_mobile_view_ = new ChromeToMobileView(this, command_updater_); |
| 254 AddChildView(chrome_to_mobile_view_); | 260 AddChildView(chrome_to_mobile_view_); |
| 255 ChromeToMobileService* service = | 261 ChromeToMobileService* service = |
| 256 ChromeToMobileServiceFactory::GetForProfile(profile_); | 262 ChromeToMobileServiceFactory::GetForProfile(profile_); |
| 257 service->RequestMobileListUpdate(); | 263 service->RequestMobileListUpdate(); |
| 258 chrome_to_mobile_view_->SetVisible(service->HasDevices()); | 264 chrome_to_mobile_view_->SetVisible(service->HasDevices()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 animation_offset_ = offset; | 350 animation_offset_ = offset; |
| 345 } | 351 } |
| 346 | 352 |
| 347 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { | 353 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { |
| 348 bool star_enabled = star_view_ && !model_->input_in_progress() && | 354 bool star_enabled = star_view_ && !model_->input_in_progress() && |
| 349 edit_bookmarks_enabled_.GetValue(); | 355 edit_bookmarks_enabled_.GetValue(); |
| 350 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); | 356 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); |
| 351 if (star_view_) | 357 if (star_view_) |
| 352 star_view_->SetVisible(star_enabled); | 358 star_view_->SetVisible(star_enabled); |
| 353 | 359 |
| 360 zoom_view_->Update(); | |
| 361 if (model_->input_in_progress()) | |
| 362 zoom_view_->SetVisible(false); | |
|
Peter Kasting
2012/06/22 20:16:20
Doesn't this need to be:
zoom_view_->SetVisible
Kyle Horimoto
2012/06/26 21:55:53
Moved this check to ZoomView::Update() :)
| |
| 363 | |
| 354 bool enabled = chrome_to_mobile_view_ && !model_->input_in_progress() && | 364 bool enabled = chrome_to_mobile_view_ && !model_->input_in_progress() && |
| 355 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasDevices(); | 365 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasDevices(); |
| 356 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); | 366 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); |
| 357 | 367 |
| 358 RefreshContentSettingViews(); | 368 RefreshContentSettingViews(); |
| 359 RefreshPageActionViews(); | 369 RefreshPageActionViews(); |
| 360 // Don't Update in app launcher mode so that the location entry does not show | 370 // Don't Update in app launcher mode so that the location entry does not show |
| 361 // a URL or security background. | 371 // a URL or security background. |
| 362 if (mode_ != APP_LAUNCHER) | 372 if (mode_ != APP_LAUNCHER) |
| 363 location_entry_->Update(tab_for_state_restoring); | 373 location_entry_->Update(tab_for_state_restoring); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 void LocationBarView::SetStarToggled(bool on) { | 454 void LocationBarView::SetStarToggled(bool on) { |
| 445 if (star_view_) | 455 if (star_view_) |
| 446 star_view_->SetToggled(on); | 456 star_view_->SetToggled(on); |
| 447 } | 457 } |
| 448 | 458 |
| 449 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { | 459 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { |
| 450 browser::ShowBookmarkBubbleView(star_view_, profile_, url, | 460 browser::ShowBookmarkBubbleView(star_view_, profile_, url, |
| 451 newly_bookmarked); | 461 newly_bookmarked); |
| 452 } | 462 } |
| 453 | 463 |
| 464 void LocationBarView::SetZoomIconTooltipPercent(int zoom_percent) { | |
| 465 if (zoom_view_) | |
|
Peter Kasting
2012/06/22 20:16:20
NULL-check no longer needed once this is created u
Kyle Horimoto
2012/06/26 21:55:53
Done.
| |
| 466 zoom_view_->SetZoomIconTooltipPercent(zoom_percent); | |
| 467 } | |
| 468 | |
| 469 void LocationBarView::SetZoomIconState( | |
| 470 ZoomController::ZoomIconState zoom_icon_state) { | |
| 471 if (zoom_view_) { | |
| 472 zoom_view_->SetZoomIconState(zoom_icon_state); | |
| 473 UpdateContentSettingsIcons(); | |
|
Peter Kasting
2012/06/22 20:16:20
Why are we calling this?
Did you instead mean to
Kyle Horimoto
2012/06/26 21:55:53
Hmm, I think this is part of some code I ended up
| |
| 474 } | |
| 475 } | |
| 476 | |
| 477 void LocationBarView::ShowZoomBubble(int zoom_percent) { | |
| 478 if (zoom_view_) | |
| 479 ZoomBubbleView::ShowBubble(zoom_view_, zoom_percent, true); | |
| 480 } | |
| 481 | |
| 454 void LocationBarView::ShowChromeToMobileBubble() { | 482 void LocationBarView::ShowChromeToMobileBubble() { |
| 455 browser::ShowChromeToMobileBubbleView(chrome_to_mobile_view_, profile_); | 483 browser::ShowChromeToMobileBubbleView(chrome_to_mobile_view_, profile_); |
| 456 } | 484 } |
| 457 | 485 |
| 458 gfx::Point LocationBarView::GetLocationEntryOrigin() const { | 486 gfx::Point LocationBarView::GetLocationEntryOrigin() const { |
| 459 gfx::Point origin(location_entry_view_->bounds().origin()); | 487 gfx::Point origin(location_entry_view_->bounds().origin()); |
| 460 // If the UI layout is RTL, the coordinate system is not transformed and | 488 // If the UI layout is RTL, the coordinate system is not transformed and |
| 461 // therefore we need to adjust the X coordinate so that bubble appears on the | 489 // therefore we need to adjust the X coordinate so that bubble appears on the |
| 462 // right hand side of the location bar. | 490 // right hand side of the location bar. |
| 463 if (base::i18n::IsRTL()) | 491 if (base::i18n::IsRTL()) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 572 // We'll adjust this width and take it out of |entry_width| below. | 600 // We'll adjust this width and take it out of |entry_width| below. |
| 573 } else { | 601 } else { |
| 574 location_icon_view_->SetVisible(true); | 602 location_icon_view_->SetVisible(true); |
| 575 location_icon_width = location_icon_view_->GetPreferredSize().width(); | 603 location_icon_width = location_icon_view_->GetPreferredSize().width(); |
| 576 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + | 604 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + |
| 577 location_icon_width + kItemEditPadding); | 605 location_icon_width + kItemEditPadding); |
| 578 } | 606 } |
| 579 | 607 |
| 580 if (star_view_ && star_view_->visible()) | 608 if (star_view_ && star_view_->visible()) |
| 581 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); | 609 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); |
| 610 if (zoom_view_ && zoom_view_->visible()) | |
|
Peter Kasting
2012/06/22 20:16:20
Nit: Remove NULL-check and move to appropriate loc
Kyle Horimoto
2012/06/26 21:55:53
Done.
| |
| 611 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding(); | |
| 582 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) | 612 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) |
| 583 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + | 613 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + |
| 584 GetItemPadding(); | 614 GetItemPadding(); |
| 585 int action_box_button_width = location_height; | 615 int action_box_button_width = location_height; |
| 586 if (action_box_button_view_) | 616 if (action_box_button_view_) |
| 587 entry_width -= action_box_button_width + GetItemPadding(); | 617 entry_width -= action_box_button_width + GetItemPadding(); |
| 588 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 618 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 589 i != page_action_views_.end(); ++i) { | 619 i != page_action_views_.end(); ++i) { |
| 590 if ((*i)->visible()) | 620 if ((*i)->visible()) |
| 591 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); | 621 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 offset -= GetEdgeItemPadding(); | 686 offset -= GetEdgeItemPadding(); |
| 657 } | 687 } |
| 658 | 688 |
| 659 if (star_view_ && star_view_->visible()) { | 689 if (star_view_ && star_view_->visible()) { |
| 660 int star_width = star_view_->GetPreferredSize().width(); | 690 int star_width = star_view_->GetPreferredSize().width(); |
| 661 offset -= star_width; | 691 offset -= star_width; |
| 662 star_view_->SetBounds(offset, location_y, star_width, location_height); | 692 star_view_->SetBounds(offset, location_y, star_width, location_height); |
| 663 offset -= GetItemPadding(); | 693 offset -= GetItemPadding(); |
| 664 } | 694 } |
| 665 | 695 |
| 696 if (zoom_view_ && zoom_view_->visible()) { | |
| 697 int zoom_width = zoom_view_->GetPreferredSize().width(); | |
| 698 offset -= zoom_width; | |
| 699 zoom_view_->SetBounds(offset, location_y, zoom_width, location_height); | |
| 700 offset -= GetItemPadding(); | |
| 701 } | |
| 702 | |
| 666 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { | 703 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { |
| 667 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); | 704 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); |
| 668 offset -= icon_width; | 705 offset -= icon_width; |
| 669 chrome_to_mobile_view_->SetBounds(offset, location_y, | 706 chrome_to_mobile_view_->SetBounds(offset, location_y, |
| 670 icon_width, location_height); | 707 icon_width, location_height); |
| 671 offset -= GetItemPadding(); | 708 offset -= GetItemPadding(); |
| 672 } | 709 } |
| 673 | 710 |
| 674 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 711 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 675 i != page_action_views_.end(); ++i) { | 712 i != page_action_views_.end(); ++i) { |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1360 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1397 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
| 1361 !suggested_text_view_->text().empty(); | 1398 !suggested_text_view_->text().empty(); |
| 1362 } | 1399 } |
| 1363 | 1400 |
| 1364 #if !defined(USE_AURA) | 1401 #if !defined(USE_AURA) |
| 1365 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | 1402 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
| 1366 return static_cast<OmniboxViewWin*>(location_entry_.get()); | 1403 return static_cast<OmniboxViewWin*>(location_entry_.get()); |
| 1367 } | 1404 } |
| 1368 #endif | 1405 #endif |
| 1369 #endif | 1406 #endif |
| OLD | NEW |