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_view.h" | |
45 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 46 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
46 #include "chrome/common/chrome_notification_types.h" | 47 #include "chrome/common/chrome_notification_types.h" |
47 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
48 #include "chrome/common/extensions/extension_switch_utils.h" | 49 #include "chrome/common/extensions/extension_switch_utils.h" |
49 #include "chrome/common/pref_names.h" | 50 #include "chrome/common/pref_names.h" |
50 #include "content/public/browser/notification_service.h" | 51 #include "content/public/browser/notification_service.h" |
51 #include "content/public/browser/render_widget_host_view.h" | 52 #include "content/public/browser/render_widget_host_view.h" |
52 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
53 #include "grit/generated_resources.h" | 54 #include "grit/generated_resources.h" |
54 #include "grit/theme_resources.h" | 55 #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)), | 142 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
142 location_icon_view_(NULL), | 143 location_icon_view_(NULL), |
143 ev_bubble_view_(NULL), | 144 ev_bubble_view_(NULL), |
144 location_entry_view_(NULL), | 145 location_entry_view_(NULL), |
145 selected_keyword_view_(NULL), | 146 selected_keyword_view_(NULL), |
146 #if defined(OS_WIN) || defined(USE_AURA) | 147 #if defined(OS_WIN) || defined(USE_AURA) |
147 suggested_text_view_(NULL), | 148 suggested_text_view_(NULL), |
148 #endif | 149 #endif |
149 keyword_hint_view_(NULL), | 150 keyword_hint_view_(NULL), |
150 star_view_(NULL), | 151 star_view_(NULL), |
152 zoom_view_(NULL), | |
151 action_box_button_view_(NULL), | 153 action_box_button_view_(NULL), |
152 chrome_to_mobile_view_(NULL), | 154 chrome_to_mobile_view_(NULL), |
153 mode_(mode), | 155 mode_(mode), |
154 show_focus_rect_(false), | 156 show_focus_rect_(false), |
155 template_url_service_(NULL), | 157 template_url_service_(NULL), |
156 animation_offset_(0) { | 158 animation_offset_(0) { |
157 set_id(VIEW_ID_LOCATION_BAR); | 159 set_id(VIEW_ID_LOCATION_BAR); |
158 | 160 |
159 if (mode_ == NORMAL) { | 161 if (mode_ == NORMAL) { |
160 painter_.reset( | 162 painter_.reset( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 action_box_button_view_ = new ActionBoxButtonView( | 241 action_box_button_view_ = new ActionBoxButtonView( |
240 ExtensionSystem::Get(profile_)->extension_service()); | 242 ExtensionSystem::Get(profile_)->extension_service()); |
241 AddChildView(action_box_button_view_); | 243 AddChildView(action_box_button_view_); |
242 } else if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { | 244 } else if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { |
243 // Note: condition above means that the star and ChromeToMobile icons are | 245 // Note: condition above means that the star and ChromeToMobile icons are |
244 // hidden in popups and in the app launcher. | 246 // hidden in popups and in the app launcher. |
245 star_view_ = new StarView(command_updater_); | 247 star_view_ = new StarView(command_updater_); |
246 AddChildView(star_view_); | 248 AddChildView(star_view_); |
247 star_view_->SetVisible(true); | 249 star_view_->SetVisible(true); |
248 | 250 |
251 zoom_view_ = new ZoomView(); | |
252 AddChildView(zoom_view_); | |
253 | |
249 // Also disable Chrome To Mobile for off-the-record and non-synced profiles, | 254 // 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. | 255 // or if the feature is disabled by a command line flag or chrome://flags. |
251 if (!profile_->IsOffTheRecord() && profile_->IsSyncAccessible() && | 256 if (!profile_->IsOffTheRecord() && profile_->IsSyncAccessible() && |
252 ChromeToMobileService::IsChromeToMobileEnabled()) { | 257 ChromeToMobileService::IsChromeToMobileEnabled()) { |
253 chrome_to_mobile_view_ = new ChromeToMobileView(this, command_updater_); | 258 chrome_to_mobile_view_ = new ChromeToMobileView(this, command_updater_); |
254 AddChildView(chrome_to_mobile_view_); | 259 AddChildView(chrome_to_mobile_view_); |
255 ChromeToMobileService* service = | 260 ChromeToMobileService* service = |
256 ChromeToMobileServiceFactory::GetForProfile(profile_); | 261 ChromeToMobileServiceFactory::GetForProfile(profile_); |
257 service->RequestMobileListUpdate(); | 262 service->RequestMobileListUpdate(); |
258 chrome_to_mobile_view_->SetVisible(service->HasDevices()); | 263 chrome_to_mobile_view_->SetVisible(service->HasDevices()); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 void LocationBarView::SetStarToggled(bool on) { | 449 void LocationBarView::SetStarToggled(bool on) { |
445 if (star_view_) | 450 if (star_view_) |
446 star_view_->SetToggled(on); | 451 star_view_->SetToggled(on); |
447 } | 452 } |
448 | 453 |
449 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { | 454 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { |
450 browser::ShowBookmarkBubbleView(star_view_, profile_, url, | 455 browser::ShowBookmarkBubbleView(star_view_, profile_, url, |
451 newly_bookmarked); | 456 newly_bookmarked); |
452 } | 457 } |
453 | 458 |
459 void LocationBarView::SetZoomIconTooltipPercent(int zoom_percent) { | |
460 if (zoom_view_) | |
461 zoom_view_->SetZoomIconTooltipPercent(zoom_percent); | |
462 } | |
463 | |
464 void LocationBarView::SetZoomIconState( | |
465 ZoomController::ZoomIconState zoom_icon_state) { | |
466 if (zoom_view_) { | |
467 zoom_view_->SetZoomIconState(zoom_icon_state); | |
468 UpdateContentSettingsIcons(); | |
469 } | |
470 } | |
471 | |
472 void LocationBarView::ShowZoomBubble(int zoom_percent) { | |
473 if (zoom_view_) | |
474 browser::ShowZoomBubbleView(zoom_view_, zoom_percent, true); | |
Ben Goodger (Google)
2012/06/04 15:16:49
is this function called from anywhere outside the
Kyle Horimoto
2012/06/05 05:03:59
Done.
| |
475 } | |
476 | |
454 void LocationBarView::ShowChromeToMobileBubble() { | 477 void LocationBarView::ShowChromeToMobileBubble() { |
455 browser::ShowChromeToMobileBubbleView(chrome_to_mobile_view_, profile_); | 478 browser::ShowChromeToMobileBubbleView(chrome_to_mobile_view_, profile_); |
456 } | 479 } |
457 | 480 |
458 gfx::Point LocationBarView::GetLocationEntryOrigin() const { | 481 gfx::Point LocationBarView::GetLocationEntryOrigin() const { |
459 gfx::Point origin(location_entry_view_->bounds().origin()); | 482 gfx::Point origin(location_entry_view_->bounds().origin()); |
460 // If the UI layout is RTL, the coordinate system is not transformed and | 483 // 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 | 484 // therefore we need to adjust the X coordinate so that bubble appears on the |
462 // right hand side of the location bar. | 485 // right hand side of the location bar. |
463 if (base::i18n::IsRTL()) | 486 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. | 595 // We'll adjust this width and take it out of |entry_width| below. |
573 } else { | 596 } else { |
574 location_icon_view_->SetVisible(true); | 597 location_icon_view_->SetVisible(true); |
575 location_icon_width = location_icon_view_->GetPreferredSize().width(); | 598 location_icon_width = location_icon_view_->GetPreferredSize().width(); |
576 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + | 599 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + |
577 location_icon_width + kItemEditPadding); | 600 location_icon_width + kItemEditPadding); |
578 } | 601 } |
579 | 602 |
580 if (star_view_ && star_view_->visible()) | 603 if (star_view_ && star_view_->visible()) |
581 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); | 604 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); |
605 if (zoom_view_ && zoom_view_->visible()) | |
606 entry_width -= zoom_view_->GetPreferredSize().width() + GetItemPadding(); | |
582 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) | 607 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) |
583 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + | 608 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + |
584 GetItemPadding(); | 609 GetItemPadding(); |
585 int action_box_button_width = location_height; | 610 int action_box_button_width = location_height; |
586 if (action_box_button_view_) | 611 if (action_box_button_view_) |
587 entry_width -= action_box_button_width + GetItemPadding(); | 612 entry_width -= action_box_button_width + GetItemPadding(); |
588 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 613 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
589 i != page_action_views_.end(); ++i) { | 614 i != page_action_views_.end(); ++i) { |
590 if ((*i)->visible()) | 615 if ((*i)->visible()) |
591 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); | 616 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 offset -= GetEdgeItemPadding(); | 681 offset -= GetEdgeItemPadding(); |
657 } | 682 } |
658 | 683 |
659 if (star_view_ && star_view_->visible()) { | 684 if (star_view_ && star_view_->visible()) { |
660 int star_width = star_view_->GetPreferredSize().width(); | 685 int star_width = star_view_->GetPreferredSize().width(); |
661 offset -= star_width; | 686 offset -= star_width; |
662 star_view_->SetBounds(offset, location_y, star_width, location_height); | 687 star_view_->SetBounds(offset, location_y, star_width, location_height); |
663 offset -= GetItemPadding(); | 688 offset -= GetItemPadding(); |
664 } | 689 } |
665 | 690 |
691 if (zoom_view_ && zoom_view_->visible()) { | |
692 int zoom_width = zoom_view_->GetPreferredSize().width(); | |
693 offset -= zoom_width; | |
694 zoom_view_->SetBounds(offset, location_y, zoom_width, location_height); | |
695 offset -= GetItemPadding(); | |
696 } | |
697 | |
666 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { | 698 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { |
667 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); | 699 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); |
668 offset -= icon_width; | 700 offset -= icon_width; |
669 chrome_to_mobile_view_->SetBounds(offset, location_y, | 701 chrome_to_mobile_view_->SetBounds(offset, location_y, |
670 icon_width, location_height); | 702 icon_width, location_height); |
671 offset -= GetItemPadding(); | 703 offset -= GetItemPadding(); |
672 } | 704 } |
673 | 705 |
674 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 706 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
675 i != page_action_views_.end(); ++i) { | 707 i != page_action_views_.end(); ++i) { |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1325 } | 1357 } |
1326 | 1358 |
1327 void LocationBarView::Observe(int type, | 1359 void LocationBarView::Observe(int type, |
1328 const content::NotificationSource& source, | 1360 const content::NotificationSource& source, |
1329 const content::NotificationDetails& details) { | 1361 const content::NotificationDetails& details) { |
1330 switch (type) { | 1362 switch (type) { |
1331 case chrome::NOTIFICATION_PREF_CHANGED: { | 1363 case chrome::NOTIFICATION_PREF_CHANGED: { |
1332 std::string* name = content::Details<std::string>(details).ptr(); | 1364 std::string* name = content::Details<std::string>(details).ptr(); |
1333 if (*name == prefs::kEditBookmarksEnabled) | 1365 if (*name == prefs::kEditBookmarksEnabled) |
1334 Update(NULL); | 1366 Update(NULL); |
1367 } | |
1335 break; | 1368 break; |
1336 } | |
1337 | |
1338 case chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED: { | 1369 case chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED: { |
1339 // Only update if the updated action box was for the active tab contents. | 1370 // Only update if the updated action box was for the active tab contents. |
1340 TabContentsWrapper* target_tab = | 1371 TabContentsWrapper* target_tab = |
1341 content::Details<TabContentsWrapper>(details).ptr(); | 1372 content::Details<TabContentsWrapper>(details).ptr(); |
1342 if (target_tab == GetTabContentsWrapper()) | 1373 if (target_tab == GetTabContentsWrapper()) |
1343 UpdatePageActions(); | 1374 UpdatePageActions(); |
1375 } | |
1344 break; | 1376 break; |
1345 } | |
1346 | |
1347 default: | 1377 default: |
1348 NOTREACHED() << "Unexpected notification."; | 1378 NOTREACHED() << "Unexpected notification."; |
1349 } | 1379 } |
1350 } | 1380 } |
1351 | 1381 |
1352 int LocationBarView::GetInternalHeight(bool use_preferred_size) { | 1382 int LocationBarView::GetInternalHeight(bool use_preferred_size) { |
1353 int total_height = | 1383 int total_height = |
1354 use_preferred_size ? GetPreferredSize().height() : height(); | 1384 use_preferred_size ? GetPreferredSize().height() : height(); |
1355 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); | 1385 return std::max(total_height - (kVerticalEdgeThickness * 2), 0); |
1356 } | 1386 } |
1357 | 1387 |
1358 #if defined(OS_WIN) || defined(USE_AURA) | 1388 #if defined(OS_WIN) || defined(USE_AURA) |
1359 bool LocationBarView::HasValidSuggestText() const { | 1389 bool LocationBarView::HasValidSuggestText() const { |
1360 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1390 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
1361 !suggested_text_view_->text().empty(); | 1391 !suggested_text_view_->text().empty(); |
1362 } | 1392 } |
1363 | 1393 |
1364 #if !defined(USE_AURA) | 1394 #if !defined(USE_AURA) |
1365 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | 1395 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
1366 return static_cast<OmniboxViewWin*>(location_entry_.get()); | 1396 return static_cast<OmniboxViewWin*>(location_entry_.get()); |
1367 } | 1397 } |
1368 #endif | 1398 #endif |
1369 #endif | 1399 #endif |
OLD | NEW |