OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/location_bar_view.h" | 5 #include "chrome/browser/views/location_bar_view.h" |
6 | 6 |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/app/chrome_dll_resource.h" | 9 #include "chrome/app/chrome_dll_resource.h" |
10 #include "chrome/browser/alternate_nav_url_fetcher.h" | 10 #include "chrome/browser/alternate_nav_url_fetcher.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 : profile_(profile), | 84 : profile_(profile), |
85 command_updater_(command_updater), | 85 command_updater_(command_updater), |
86 model_(model), | 86 model_(model), |
87 delegate_(delegate), | 87 delegate_(delegate), |
88 disposition_(CURRENT_TAB), | 88 disposition_(CURRENT_TAB), |
89 location_entry_view_(NULL), | 89 location_entry_view_(NULL), |
90 selected_keyword_view_(profile), | 90 selected_keyword_view_(profile), |
91 keyword_hint_view_(profile), | 91 keyword_hint_view_(profile), |
92 type_to_search_view_(l10n_util::GetString(IDS_OMNIBOX_EMPTY_TEXT)), | 92 type_to_search_view_(l10n_util::GetString(IDS_OMNIBOX_EMPTY_TEXT)), |
93 security_image_view_(profile, model), | 93 security_image_view_(profile, model), |
| 94 rss_image_view_(model), |
94 popup_window_mode_(popup_window_mode), | 95 popup_window_mode_(popup_window_mode), |
95 first_run_bubble_(this) { | 96 first_run_bubble_(this) { |
96 DCHECK(profile_); | 97 DCHECK(profile_); |
97 SetID(VIEW_ID_LOCATION_BAR); | 98 SetID(VIEW_ID_LOCATION_BAR); |
98 SetFocusable(true); | 99 SetFocusable(true); |
99 | 100 |
100 if (!kBackground) { | 101 if (!kBackground) { |
101 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); | 102 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); |
102 kBackground = rb.GetBitmapNamed(IDR_LOCATIONBG); | 103 kBackground = rb.GetBitmapNamed(IDR_LOCATIONBG); |
103 kPopupBackground = rb.GetBitmapNamed(IDR_LOCATIONBG_POPUPMODE_CENTER); | 104 kPopupBackground = rb.GetBitmapNamed(IDR_LOCATIONBG_POPUPMODE_CENTER); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 type_to_search_view_.SetFont(font_); | 147 type_to_search_view_.SetFont(font_); |
147 type_to_search_view_.SetColor(gray); | 148 type_to_search_view_.SetColor(gray); |
148 type_to_search_view_.SetParentOwned(false); | 149 type_to_search_view_.SetParentOwned(false); |
149 | 150 |
150 AddChildView(&keyword_hint_view_); | 151 AddChildView(&keyword_hint_view_); |
151 keyword_hint_view_.SetVisible(false); | 152 keyword_hint_view_.SetVisible(false); |
152 keyword_hint_view_.SetFont(font_); | 153 keyword_hint_view_.SetFont(font_); |
153 keyword_hint_view_.SetColor(gray); | 154 keyword_hint_view_.SetColor(gray); |
154 keyword_hint_view_.SetParentOwned(false); | 155 keyword_hint_view_.SetParentOwned(false); |
155 | 156 |
| 157 AddChildView(&rss_image_view_); |
| 158 rss_image_view_.SetVisible(false); |
| 159 rss_image_view_.SetParentOwned(false); |
| 160 |
156 AddChildView(&security_image_view_); | 161 AddChildView(&security_image_view_); |
157 security_image_view_.SetVisible(false); | 162 security_image_view_.SetVisible(false); |
158 security_image_view_.SetParentOwned(false); | 163 security_image_view_.SetParentOwned(false); |
159 | 164 |
160 AddChildView(&info_label_); | 165 AddChildView(&info_label_); |
161 info_label_.SetVisible(false); | 166 info_label_.SetVisible(false); |
162 info_label_.SetParentOwned(false); | 167 info_label_.SetParentOwned(false); |
163 | 168 |
164 // Notify us when any ancestor is resized. In this case we want to tell the | 169 // Notify us when any ancestor is resized. In this case we want to tell the |
165 // AutocompleteEditView to close its popup. | 170 // AutocompleteEditView to close its popup. |
166 SetNotifyWhenVisibleBoundsInRootChanges(true); | 171 SetNotifyWhenVisibleBoundsInRootChanges(true); |
167 | 172 |
168 // Initialize the location entry. We do this to avoid a black flash which is | 173 // Initialize the location entry. We do this to avoid a black flash which is |
169 // visible when the location entry has just been initialized. | 174 // visible when the location entry has just been initialized. |
170 Update(NULL); | 175 Update(NULL); |
171 | 176 |
172 OnChanged(); | 177 OnChanged(); |
173 } | 178 } |
174 | 179 |
175 void LocationBarView::Update(const TabContents* tab_for_state_restoring) { | 180 void LocationBarView::Update(const TabContents* tab_for_state_restoring) { |
176 SetSecurityIcon(model_->GetIcon()); | 181 SetSecurityIcon(model_->GetIcon()); |
| 182 SetRssIconVisibility(model_->GetFeedList().get()); |
177 std::wstring info_text, info_tooltip; | 183 std::wstring info_text, info_tooltip; |
178 SkColor text_color; | 184 SkColor text_color; |
179 model_->GetInfoText(&info_text, &text_color, &info_tooltip); | 185 model_->GetInfoText(&info_text, &text_color, &info_tooltip); |
180 SetInfoText(info_text, text_color, info_tooltip); | 186 SetInfoText(info_text, text_color, info_tooltip); |
181 location_entry_->Update(tab_for_state_restoring); | 187 location_entry_->Update(tab_for_state_restoring); |
182 Layout(); | 188 Layout(); |
183 SchedulePaint(); | 189 SchedulePaint(); |
184 } | 190 } |
185 | 191 |
| 192 void LocationBarView::UpdateFeedIcon() { |
| 193 SetRssIconVisibility(model_->GetFeedList().get()); |
| 194 Layout(); |
| 195 SchedulePaint(); |
| 196 } |
| 197 |
186 void LocationBarView::Focus() { | 198 void LocationBarView::Focus() { |
187 ::SetFocus(location_entry_->m_hWnd); | 199 ::SetFocus(location_entry_->m_hWnd); |
188 } | 200 } |
189 | 201 |
190 void LocationBarView::SetProfile(Profile* profile) { | 202 void LocationBarView::SetProfile(Profile* profile) { |
191 DCHECK(profile); | 203 DCHECK(profile); |
192 if (profile_ != profile) { | 204 if (profile_ != profile) { |
193 profile_ = profile; | 205 profile_ = profile; |
194 location_entry_->model()->SetProfile(profile); | 206 location_entry_->model()->SetProfile(profile); |
195 selected_keyword_view_.set_profile(profile); | 207 selected_keyword_view_.set_profile(profile); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 void LocationBarView::DoLayout(const bool force_layout) { | 340 void LocationBarView::DoLayout(const bool force_layout) { |
329 if (!location_entry_.get()) | 341 if (!location_entry_.get()) |
330 return; | 342 return; |
331 | 343 |
332 RECT formatting_rect; | 344 RECT formatting_rect; |
333 location_entry_->GetRect(&formatting_rect); | 345 location_entry_->GetRect(&formatting_rect); |
334 RECT edit_bounds; | 346 RECT edit_bounds; |
335 location_entry_->GetClientRect(&edit_bounds); | 347 location_entry_->GetClientRect(&edit_bounds); |
336 | 348 |
337 int entry_width = width() - (kEntryPadding * 2); | 349 int entry_width = width() - (kEntryPadding * 2); |
| 350 |
| 351 gfx::Size rss_image_size; |
| 352 if (rss_image_view_.IsVisible()) { |
| 353 rss_image_size = rss_image_view_.GetPreferredSize(); |
| 354 entry_width -= rss_image_size.width(); |
| 355 } |
338 gfx::Size security_image_size; | 356 gfx::Size security_image_size; |
339 if (security_image_view_.IsVisible()) { | 357 if (security_image_view_.IsVisible()) { |
340 security_image_size = security_image_view_.GetPreferredSize(); | 358 security_image_size = security_image_view_.GetPreferredSize(); |
341 entry_width -= security_image_size.width(); | 359 entry_width -= security_image_size.width() + kInnerPadding; |
342 } | 360 } |
343 gfx::Size info_label_size; | 361 gfx::Size info_label_size; |
344 if (info_label_.IsVisible()) { | 362 if (info_label_.IsVisible()) { |
345 info_label_size = info_label_.GetPreferredSize(); | 363 info_label_size = info_label_.GetPreferredSize(); |
346 entry_width -= (info_label_size.width() + kInnerPadding); | 364 entry_width -= (info_label_size.width() + kInnerPadding); |
347 } | 365 } |
348 | 366 |
349 const int max_edit_width = entry_width - formatting_rect.left - | 367 const int max_edit_width = entry_width - formatting_rect.left - |
350 (edit_bounds.right - formatting_rect.right); | 368 (edit_bounds.right - formatting_rect.right); |
351 if (max_edit_width < 0) | 369 if (max_edit_width < 0) |
352 return; | 370 return; |
353 const int text_width = TextDisplayWidth(); | 371 const int text_width = TextDisplayWidth(); |
354 bool needs_layout = force_layout; | 372 bool needs_layout = force_layout; |
355 needs_layout |= AdjustHints(text_width, max_edit_width); | 373 needs_layout |= AdjustHints(text_width, max_edit_width); |
356 | 374 |
357 if (!needs_layout) | 375 if (!needs_layout) |
358 return; | 376 return; |
359 | 377 |
360 // TODO(sky): baseline layout. | 378 // TODO(sky): baseline layout. |
361 int location_y = TopMargin(); | 379 int location_y = TopMargin(); |
362 int location_height = std::max(height() - location_y - kVertMargin, 0); | 380 int location_height = std::max(height() - location_y - kVertMargin, 0); |
363 if (info_label_.IsVisible()) { | 381 if (info_label_.IsVisible()) { |
364 info_label_.SetBounds(width() - kEntryPadding - info_label_size.width(), | 382 info_label_.SetBounds(width() - kEntryPadding - info_label_size.width(), |
365 location_y, | 383 location_y, |
366 info_label_size.width(), location_height); | 384 info_label_size.width(), location_height); |
367 } | 385 } |
| 386 const int info_label_width = info_label_size.width() ? |
| 387 info_label_size.width() + kInnerPadding : 0; |
| 388 if (rss_image_view_.IsVisible()) { |
| 389 rss_image_view_.SetBounds(width() - kEntryPadding - |
| 390 info_label_width - |
| 391 security_image_size.width() - |
| 392 rss_image_size.width(), |
| 393 location_y, |
| 394 rss_image_size.width(), |
| 395 location_height); |
| 396 } |
368 if (security_image_view_.IsVisible()) { | 397 if (security_image_view_.IsVisible()) { |
369 const int info_label_width = info_label_size.width() ? | |
370 info_label_size.width() + kInnerPadding : 0; | |
371 security_image_view_.SetBounds(width() - kEntryPadding - info_label_width - | 398 security_image_view_.SetBounds(width() - kEntryPadding - info_label_width - |
372 security_image_size.width(), location_y, security_image_size.width(), | 399 security_image_size.width(), location_y, security_image_size.width(), |
373 location_height); | 400 location_height); |
374 } | 401 } |
375 gfx::Rect location_bounds(kEntryPadding, location_y, entry_width, | 402 gfx::Rect location_bounds(kEntryPadding, location_y, entry_width, |
376 location_height); | 403 location_height); |
377 if (selected_keyword_view_.IsVisible()) { | 404 if (selected_keyword_view_.IsVisible()) { |
378 LayoutView(true, &selected_keyword_view_, text_width, max_edit_width, | 405 LayoutView(true, &selected_keyword_view_, text_width, max_edit_width, |
379 &location_bounds); | 406 &location_bounds); |
380 } else if (keyword_hint_view_.IsVisible()) { | 407 } else if (keyword_hint_view_.IsVisible()) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 case ToolbarModel::NO_ICON: | 518 case ToolbarModel::NO_ICON: |
492 security_image_view_.SetVisible(false); | 519 security_image_view_.SetVisible(false); |
493 break; | 520 break; |
494 default: | 521 default: |
495 NOTREACHED(); | 522 NOTREACHED(); |
496 security_image_view_.SetVisible(false); | 523 security_image_view_.SetVisible(false); |
497 break; | 524 break; |
498 } | 525 } |
499 } | 526 } |
500 | 527 |
| 528 void LocationBarView::SetRssIconVisibility(FeedList* feeds) { |
| 529 bool show_rss = feeds && feeds->list().size() > 0; |
| 530 // TODO(finnur): Enable this when we have a good landing page to show feeds. |
| 531 rss_image_view_.SetVisible(false); |
| 532 } |
| 533 |
501 void LocationBarView::SetInfoText(const std::wstring& text, | 534 void LocationBarView::SetInfoText(const std::wstring& text, |
502 SkColor text_color, | 535 SkColor text_color, |
503 const std::wstring& tooltip_text) { | 536 const std::wstring& tooltip_text) { |
504 info_label_.SetVisible(!text.empty()); | 537 info_label_.SetVisible(!text.empty()); |
505 info_label_.SetText(text); | 538 info_label_.SetText(text); |
506 info_label_.SetColor(text_color); | 539 info_label_.SetColor(text_color); |
507 info_label_.SetTooltipText(tooltip_text); | 540 info_label_.SetTooltipText(tooltip_text); |
508 } | 541 } |
509 | 542 |
510 bool LocationBarView::ToggleVisibility(bool new_vis, View* view) { | 543 bool LocationBarView::ToggleVisibility(bool new_vis, View* view) { |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 if (!e.IsAltDown()) | 797 if (!e.IsAltDown()) |
765 return true; | 798 return true; |
766 | 799 |
767 return !win_util::IsNumPadDigit(e.GetCharacter(), e.IsExtendedKey()); | 800 return !win_util::IsNumPadDigit(e.GetCharacter(), e.IsExtendedKey()); |
768 } | 801 } |
769 | 802 |
770 // ShowInfoBubbleTask----------------------------------------------------------- | 803 // ShowInfoBubbleTask----------------------------------------------------------- |
771 | 804 |
772 class LocationBarView::ShowInfoBubbleTask : public Task { | 805 class LocationBarView::ShowInfoBubbleTask : public Task { |
773 public: | 806 public: |
774 explicit ShowInfoBubbleTask(LocationBarView::SecurityImageView* image_view); | 807 explicit ShowInfoBubbleTask( |
| 808 LocationBarView::LocationBarImageView* image_view); |
775 virtual void Run(); | 809 virtual void Run(); |
776 void Cancel(); | 810 void Cancel(); |
777 | 811 |
778 private: | 812 private: |
779 LocationBarView::SecurityImageView* image_view_; | 813 LocationBarView::LocationBarImageView* image_view_; |
780 bool cancelled_; | 814 bool cancelled_; |
781 | 815 |
782 DISALLOW_EVIL_CONSTRUCTORS(ShowInfoBubbleTask); | 816 DISALLOW_EVIL_CONSTRUCTORS(ShowInfoBubbleTask); |
783 }; | 817 }; |
784 | 818 |
785 LocationBarView::ShowInfoBubbleTask::ShowInfoBubbleTask( | 819 LocationBarView::ShowInfoBubbleTask::ShowInfoBubbleTask( |
786 LocationBarView::SecurityImageView* image_view) | 820 LocationBarView::LocationBarImageView* image_view) |
787 : cancelled_(false), | 821 : cancelled_(false), |
788 image_view_(image_view) { | 822 image_view_(image_view) { |
789 } | 823 } |
790 | 824 |
791 void LocationBarView::ShowInfoBubbleTask::Run() { | 825 void LocationBarView::ShowInfoBubbleTask::Run() { |
792 if (cancelled_) | 826 if (cancelled_) |
793 return; | 827 return; |
794 | 828 |
795 if (!image_view_->GetWidget()->IsActive()) { | 829 if (!image_view_->GetWidget()->IsActive()) { |
796 // The browser is no longer active. Let's not show the info bubble, this | 830 // The browser is no longer active. Let's not show the info bubble, this |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 // Moving the bounds "backwards" so that it appears within the location bar | 869 // Moving the bounds "backwards" so that it appears within the location bar |
836 // if the UI layout is RTL. | 870 // if the UI layout is RTL. |
837 if (UILayoutIsRightToLeft()) | 871 if (UILayoutIsRightToLeft()) |
838 bounds.set_x(location.x() - 20); | 872 bounds.set_x(location.x() - 20); |
839 | 873 |
840 FirstRunBubble::Show(profile_, | 874 FirstRunBubble::Show(profile_, |
841 location_entry_view_->GetRootView()->GetWidget()->GetNativeView(), | 875 location_entry_view_->GetRootView()->GetWidget()->GetNativeView(), |
842 bounds); | 876 bounds); |
843 } | 877 } |
844 | 878 |
845 // SecurityImageView------------------------------------------------------------ | 879 // LocationBarImageView--------------------------------------------------------- |
846 | 880 |
847 // static | 881 LocationBarView::LocationBarImageView::LocationBarImageView() |
848 SkBitmap* LocationBarView::SecurityImageView::lock_icon_ = NULL; | 882 : show_info_bubble_task_(NULL), |
849 SkBitmap* LocationBarView::SecurityImageView::warning_icon_ = NULL; | 883 info_bubble_(NULL) { |
850 | |
851 LocationBarView::SecurityImageView::SecurityImageView(Profile* profile, | |
852 ToolbarModel* model) | |
853 : profile_(profile), | |
854 model_(model), | |
855 show_info_bubble_task_(NULL), | |
856 info_bubble_(NULL) { | |
857 if (!lock_icon_) { | |
858 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
859 lock_icon_ = rb.GetBitmapNamed(IDR_LOCK); | |
860 warning_icon_ = rb.GetBitmapNamed(IDR_WARNING); | |
861 } | |
862 SetImageShown(LOCK); | |
863 } | 884 } |
864 | 885 |
865 LocationBarView::SecurityImageView::~SecurityImageView() { | 886 LocationBarView::LocationBarImageView::~LocationBarImageView() { |
866 if (show_info_bubble_task_) | 887 if (show_info_bubble_task_) |
867 show_info_bubble_task_->Cancel(); | 888 show_info_bubble_task_->Cancel(); |
868 | 889 |
869 if (info_bubble_) { | 890 if (info_bubble_) { |
870 // We are going to be invalid, make sure the InfoBubble does not keep a | 891 // We are going to be invalid, make sure the InfoBubble does not keep a |
871 // pointer to us. | 892 // pointer to us. |
872 info_bubble_->SetDelegate(NULL); | 893 info_bubble_->SetDelegate(NULL); |
873 } | 894 } |
874 } | 895 } |
875 | 896 |
876 void LocationBarView::SecurityImageView::SetImageShown(Image image) { | 897 void LocationBarView::LocationBarImageView::OnMouseMoved( |
877 switch (image) { | 898 const views::MouseEvent& event) { |
878 case LOCK: | 899 if (show_info_bubble_task_) { |
879 ImageView::SetImage(lock_icon_); | 900 show_info_bubble_task_->Cancel(); |
880 break; | 901 show_info_bubble_task_ = NULL; |
881 case WARNING: | |
882 ImageView::SetImage(warning_icon_); | |
883 break; | |
884 default: | |
885 NOTREACHED(); | |
886 break; | |
887 } | 902 } |
| 903 |
| 904 if (info_bubble_) { |
| 905 // If an info bubble is currently showing, nothing to do. |
| 906 return; |
| 907 } |
| 908 |
| 909 show_info_bubble_task_ = new ShowInfoBubbleTask(this); |
| 910 MessageLoop::current()->PostDelayedTask(FROM_HERE, show_info_bubble_task_, |
| 911 kInfoBubbleHoverDelayMs); |
888 } | 912 } |
889 | 913 |
890 void LocationBarView::SecurityImageView::ShowInfoBubble() { | 914 void LocationBarView::LocationBarImageView::OnMouseExited( |
891 std::wstring text; | 915 const views::MouseEvent& event) { |
892 SkColor text_color; | 916 if (show_info_bubble_task_) { |
893 model_->GetIconHoverText(&text, &text_color); | 917 show_info_bubble_task_->Cancel(); |
| 918 show_info_bubble_task_ = NULL; |
| 919 } |
894 | 920 |
| 921 if (info_bubble_) |
| 922 info_bubble_->Close(); |
| 923 } |
| 924 |
| 925 void LocationBarView::LocationBarImageView::InfoBubbleClosing( |
| 926 InfoBubble* info_bubble, bool closed_by_escape) { |
| 927 info_bubble_ = NULL; |
| 928 } |
| 929 |
| 930 void LocationBarView::LocationBarImageView::ShowInfoBubbleImpl( |
| 931 const std::wstring& text, SkColor text_color) { |
895 gfx::Point location; | 932 gfx::Point location; |
896 views::View::ConvertPointToScreen(this, &location); | 933 views::View::ConvertPointToScreen(this, &location); |
897 gfx::Rect bounds(location.x(), location.y(), width(), height()); | 934 gfx::Rect bounds(location.x(), location.y(), width(), height()); |
898 | 935 |
899 views::Label* label = new views::Label(text); | 936 views::Label* label = new views::Label(text); |
900 label->SetMultiLine(true); | 937 label->SetMultiLine(true); |
901 label->SetColor(text_color); | 938 label->SetColor(text_color); |
902 label->SetFont(ResourceBundle::GetSharedInstance().GetFont( | 939 label->SetFont(ResourceBundle::GetSharedInstance().GetFont( |
903 ResourceBundle::BaseFont).DeriveFont(2)); | 940 ResourceBundle::BaseFont).DeriveFont(2)); |
904 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 941 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
905 label->SizeToFit(0); | 942 label->SizeToFit(0); |
906 DCHECK(info_bubble_ == NULL); | 943 DCHECK(info_bubble_ == NULL); |
907 info_bubble_ = InfoBubble::Show(GetRootView()->GetWidget()->GetNativeView(), | 944 info_bubble_ = InfoBubble::Show(GetRootView()->GetWidget()->GetNativeView(), |
908 bounds, label, this); | 945 bounds, label, this); |
909 show_info_bubble_task_ = NULL; | 946 show_info_bubble_task_ = NULL; |
910 } | 947 } |
911 | 948 |
912 void LocationBarView::SecurityImageView::OnMouseMoved( | 949 // SecurityImageView------------------------------------------------------------ |
913 const views::MouseEvent& event) { | 950 |
914 if (show_info_bubble_task_) { | 951 // static |
915 show_info_bubble_task_->Cancel(); | 952 SkBitmap* LocationBarView::SecurityImageView::lock_icon_ = NULL; |
916 show_info_bubble_task_ = NULL; | 953 SkBitmap* LocationBarView::SecurityImageView::warning_icon_ = NULL; |
| 954 |
| 955 LocationBarView::SecurityImageView::SecurityImageView(Profile* profile, |
| 956 ToolbarModel* model) |
| 957 : LocationBarImageView(), |
| 958 profile_(profile), |
| 959 model_(model) { |
| 960 if (!lock_icon_) { |
| 961 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 962 lock_icon_ = rb.GetBitmapNamed(IDR_LOCK); |
| 963 warning_icon_ = rb.GetBitmapNamed(IDR_WARNING); |
917 } | 964 } |
918 | 965 SetImageShown(LOCK); |
919 if (info_bubble_) { | |
920 // If an info bubble is currently showing, nothing to do. | |
921 return; | |
922 } | |
923 | |
924 show_info_bubble_task_ = new ShowInfoBubbleTask(this); | |
925 MessageLoop::current()->PostDelayedTask(FROM_HERE, show_info_bubble_task_, | |
926 kInfoBubbleHoverDelayMs); | |
927 } | 966 } |
928 | 967 |
929 void LocationBarView::SecurityImageView::OnMouseExited( | 968 LocationBarView::SecurityImageView::~SecurityImageView() { |
930 const views::MouseEvent& event) { | 969 } |
931 if (show_info_bubble_task_) { | 970 |
932 show_info_bubble_task_->Cancel(); | 971 void LocationBarView::SecurityImageView::SetImageShown(Image image) { |
933 show_info_bubble_task_ = NULL; | 972 switch (image) { |
| 973 case LOCK: |
| 974 ImageView::SetImage(lock_icon_); |
| 975 break; |
| 976 case WARNING: |
| 977 ImageView::SetImage(warning_icon_); |
| 978 break; |
| 979 default: |
| 980 NOTREACHED(); |
| 981 break; |
934 } | 982 } |
935 | |
936 if (info_bubble_) | |
937 info_bubble_->Close(); | |
938 } | 983 } |
939 | 984 |
940 bool LocationBarView::SecurityImageView::OnMousePressed( | 985 bool LocationBarView::SecurityImageView::OnMousePressed( |
941 const views::MouseEvent& event) { | 986 const views::MouseEvent& event) { |
942 NavigationEntry* nav_entry = | 987 NavigationEntry* nav_entry = |
943 BrowserList::GetLastActive()->GetSelectedTabContents()-> | 988 BrowserList::GetLastActive()->GetSelectedTabContents()-> |
944 controller()->GetActiveEntry(); | 989 controller()->GetActiveEntry(); |
945 if (!nav_entry) { | 990 if (!nav_entry) { |
946 NOTREACHED(); | 991 NOTREACHED(); |
947 return true; | 992 return true; |
948 } | 993 } |
949 PageInfoWindow::CreatePageInfo(profile_, | 994 PageInfoWindow::CreatePageInfo(profile_, |
950 nav_entry, | 995 nav_entry, |
951 GetRootView()->GetWidget()->GetNativeView(), | 996 GetRootView()->GetWidget()->GetNativeView(), |
952 PageInfoWindow::SECURITY); | 997 PageInfoWindow::SECURITY); |
953 return true; | 998 return true; |
954 } | 999 } |
955 | 1000 |
956 void LocationBarView::SecurityImageView::InfoBubbleClosing( | 1001 void LocationBarView::SecurityImageView::ShowInfoBubble() { |
957 InfoBubble* info_bubble, | 1002 std::wstring text; |
958 bool closed_by_escape) { | 1003 SkColor text_color; |
959 info_bubble_ = NULL; | 1004 model_->GetIconHoverText(&text, &text_color); |
| 1005 |
| 1006 ShowInfoBubbleImpl(text, text_color); |
| 1007 } |
| 1008 |
| 1009 // RssImageView------------------------------------------------------------ |
| 1010 |
| 1011 // static |
| 1012 SkBitmap* LocationBarView::RssImageView::rss_icon_ = NULL; |
| 1013 |
| 1014 LocationBarView::RssImageView::RssImageView(ToolbarModel* model) |
| 1015 : model_(model), |
| 1016 LocationBarImageView() { |
| 1017 if (!rss_icon_) { |
| 1018 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1019 rss_icon_ = rb.GetBitmapNamed(IDR_RSS_ICON); |
| 1020 } |
| 1021 ImageView::SetImage(rss_icon_); |
| 1022 } |
| 1023 |
| 1024 LocationBarView::RssImageView::~RssImageView() { |
| 1025 } |
| 1026 |
| 1027 bool LocationBarView::RssImageView::OnMousePressed( |
| 1028 const views::MouseEvent& event) { |
| 1029 NavigationEntry* entry = |
| 1030 BrowserList::GetLastActive()->GetSelectedTabContents()-> |
| 1031 controller()->GetActiveEntry(); |
| 1032 if (!entry) { |
| 1033 NOTREACHED(); |
| 1034 return true; |
| 1035 } |
| 1036 |
| 1037 // Navigate to the first item in the feed list. |
| 1038 scoped_refptr<FeedList> feeds = model_->GetFeedList(); |
| 1039 DCHECK(feeds.get() && feeds->list().size() > 0); |
| 1040 |
| 1041 // TODO(finnur): Make this do more than just display the XML in the browser. |
| 1042 BrowserList::GetLastActive()->OpenURL(feeds->list()[0].url, GURL(), |
| 1043 CURRENT_TAB, PageTransition::LINK); |
| 1044 return true; |
| 1045 } |
| 1046 |
| 1047 void LocationBarView::RssImageView::ShowInfoBubble() { |
| 1048 // TODO(finnur): Get this string from the resources. |
| 1049 std::wstring text = L"Subscribe to this feed"; |
| 1050 SkColor text_color = SK_ColorBLUE; |
| 1051 ShowInfoBubbleImpl(text, text_color); |
960 } | 1052 } |
961 | 1053 |
962 bool LocationBarView::OverrideAccelerator( | 1054 bool LocationBarView::OverrideAccelerator( |
963 const views::Accelerator& accelerator) { | 1055 const views::Accelerator& accelerator) { |
964 return location_entry_->OverrideAccelerator(accelerator); | 1056 return location_entry_->OverrideAccelerator(accelerator); |
965 } | 1057 } |
966 | 1058 |
967 //////////////////////////////////////////////////////////////////////////////// | 1059 //////////////////////////////////////////////////////////////////////////////// |
968 // LocationBarView, LocationBar implementation: | 1060 // LocationBarView, LocationBar implementation: |
969 | 1061 |
(...skipping 26 matching lines...) Expand all Loading... |
996 } | 1088 } |
997 | 1089 |
998 void LocationBarView::FocusSearch() { | 1090 void LocationBarView::FocusSearch() { |
999 location_entry_->SetUserText(L"?"); | 1091 location_entry_->SetUserText(L"?"); |
1000 location_entry_->SetFocus(); | 1092 location_entry_->SetFocus(); |
1001 } | 1093 } |
1002 | 1094 |
1003 void LocationBarView::SaveStateToContents(TabContents* contents) { | 1095 void LocationBarView::SaveStateToContents(TabContents* contents) { |
1004 location_entry_->SaveStateToTab(contents); | 1096 location_entry_->SaveStateToTab(contents); |
1005 } | 1097 } |
OLD | NEW |