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/gtk/location_bar_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 namespace { | 77 namespace { |
78 | 78 |
79 // We are positioned with a little bit of extra space that we don't use now. | 79 // We are positioned with a little bit of extra space that we don't use now. |
80 const int kTopMargin = 1; | 80 const int kTopMargin = 1; |
81 const int kBottomMargin = 1; | 81 const int kBottomMargin = 1; |
82 const int kLeftMargin = 1; | 82 const int kLeftMargin = 1; |
83 const int kRightMargin = 1; | 83 const int kRightMargin = 1; |
84 // We draw a border on the top and bottom (but not on left or right). | 84 // We draw a border on the top and bottom (but not on left or right). |
85 const int kBorderThickness = 1; | 85 const int kBorderThickness = 1; |
86 | 86 |
87 // Left margin of first run bubble. | |
88 const int kFirstRunBubbleLeftMargin = 8; | |
89 // Extra vertical spacing for first run bubble. | |
90 const int kFirstRunBubbleTopMargin = 5; | |
91 // Spacing needed to align the bubble with the left side of the omnibox. | 87 // Spacing needed to align the bubble with the left side of the omnibox. |
92 const int kFirstRunBubbleLeftSpacing = 4; | 88 const int kFirstRunBubbleLeftSpacing = 4; |
93 | 89 |
94 // The padding around the top, bottom, and sides of the location bar hbox. | 90 // The padding around the top, bottom, and sides of the location bar hbox. |
95 // We don't want to edit control's text to be right against the edge, | 91 // We don't want to edit control's text to be right against the edge, |
96 // as well the tab to search box and other widgets need to have the padding on | 92 // as well the tab to search box and other widgets need to have the padding on |
97 // top and bottom to avoid drawing larger than the location bar space. | 93 // top and bottom to avoid drawing larger than the location bar space. |
98 const int kHboxBorder = 2; | 94 const int kHboxBorder = 2; |
99 | 95 |
100 // Padding between the elements in the bar. | 96 // Padding between the elements in the bar. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 tab_to_search_hint_leading_label_(NULL), | 163 tab_to_search_hint_leading_label_(NULL), |
168 tab_to_search_hint_icon_(NULL), | 164 tab_to_search_hint_icon_(NULL), |
169 tab_to_search_hint_trailing_label_(NULL), | 165 tab_to_search_hint_trailing_label_(NULL), |
170 command_updater_(browser->command_updater()), | 166 command_updater_(browser->command_updater()), |
171 toolbar_model_(browser->toolbar_model()), | 167 toolbar_model_(browser->toolbar_model()), |
172 browser_(browser), | 168 browser_(browser), |
173 disposition_(CURRENT_TAB), | 169 disposition_(CURRENT_TAB), |
174 transition_(content::PageTransitionFromInt( | 170 transition_(content::PageTransitionFromInt( |
175 content::PAGE_TRANSITION_TYPED | | 171 content::PAGE_TRANSITION_TYPED | |
176 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), | 172 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
177 first_run_bubble_(this), | 173 weak_ptr_factory_(this), |
178 popup_window_mode_(false), | 174 popup_window_mode_(false), |
179 theme_service_(NULL), | 175 theme_service_(NULL), |
180 hbox_width_(0), | 176 hbox_width_(0), |
181 entry_box_width_(0), | 177 entry_box_width_(0), |
182 show_selected_keyword_(false), | 178 show_selected_keyword_(false), |
183 show_keyword_hint_(false) { | 179 show_keyword_hint_(false) { |
184 } | 180 } |
185 | 181 |
186 LocationBarViewGtk::~LocationBarViewGtk() { | 182 LocationBarViewGtk::~LocationBarViewGtk() { |
187 // All of our widgets should have be children of / owned by the alignment. | 183 // All of our widgets should have be children of / owned by the alignment. |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 } | 575 } |
580 | 576 |
581 InstantController* LocationBarViewGtk::GetInstant() { | 577 InstantController* LocationBarViewGtk::GetInstant() { |
582 return browser_->instant(); | 578 return browser_->instant(); |
583 } | 579 } |
584 | 580 |
585 TabContentsWrapper* LocationBarViewGtk::GetTabContentsWrapper() const { | 581 TabContentsWrapper* LocationBarViewGtk::GetTabContentsWrapper() const { |
586 return browser_->GetSelectedTabContentsWrapper(); | 582 return browser_->GetSelectedTabContentsWrapper(); |
587 } | 583 } |
588 | 584 |
589 void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { | 585 void LocationBarViewGtk::ShowFirstRunBubble() { |
590 // We need the browser window to be shown before we can show the bubble, but | 586 // We need the browser window to be shown before we can show the bubble, but |
591 // we get called before that's happened. | 587 // we get called before that's happened. |
592 MessageLoop::current()->PostTask( | 588 MessageLoop::current()->PostTask( |
593 FROM_HERE, | 589 FROM_HERE, |
594 base::Bind(&LocationBarViewGtk::ShowFirstRunBubbleInternal, | 590 base::Bind(&LocationBarViewGtk::ShowFirstRunBubbleInternal, |
595 first_run_bubble_.GetWeakPtr(), | 591 weak_ptr_factory_.GetWeakPtr())); |
596 bubble_type)); | |
597 } | 592 } |
598 | 593 |
599 void LocationBarViewGtk::SetSuggestedText(const string16& text, | 594 void LocationBarViewGtk::SetSuggestedText(const string16& text, |
600 InstantCompleteBehavior behavior) { | 595 InstantCompleteBehavior behavior) { |
601 location_entry_->model()->SetSuggestedText(text, behavior); | 596 location_entry_->model()->SetSuggestedText(text, behavior); |
602 } | 597 } |
603 | 598 |
604 string16 LocationBarViewGtk::GetInputString() const { | 599 string16 LocationBarViewGtk::GetInputString() const { |
605 return location_input_; | 600 return location_input_; |
606 } | 601 } |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 std::string leading(UTF16ToUTF8( | 1010 std::string leading(UTF16ToUTF8( |
1016 keyword_hint.substr(0, content_param_offsets.front()))); | 1011 keyword_hint.substr(0, content_param_offsets.front()))); |
1017 std::string trailing(UTF16ToUTF8( | 1012 std::string trailing(UTF16ToUTF8( |
1018 keyword_hint.substr(content_param_offsets.front()))); | 1013 keyword_hint.substr(content_param_offsets.front()))); |
1019 gtk_label_set_text(GTK_LABEL(tab_to_search_hint_leading_label_), | 1014 gtk_label_set_text(GTK_LABEL(tab_to_search_hint_leading_label_), |
1020 leading.c_str()); | 1015 leading.c_str()); |
1021 gtk_label_set_text(GTK_LABEL(tab_to_search_hint_trailing_label_), | 1016 gtk_label_set_text(GTK_LABEL(tab_to_search_hint_trailing_label_), |
1022 trailing.c_str()); | 1017 trailing.c_str()); |
1023 } | 1018 } |
1024 | 1019 |
1025 void LocationBarViewGtk::ShowFirstRunBubbleInternal( | 1020 void LocationBarViewGtk::ShowFirstRunBubbleInternal() { |
1026 FirstRun::BubbleType bubble_type) { | |
1027 if (!location_entry_.get() || !widget()->window) | 1021 if (!location_entry_.get() || !widget()->window) |
1028 return; | 1022 return; |
1029 | 1023 |
1030 gfx::Rect bounds = gtk_util::WidgetBounds(location_icon_image_); | 1024 gfx::Rect bounds = gtk_util::WidgetBounds(location_icon_image_); |
1031 bounds.set_x(bounds.x() + kFirstRunBubbleLeftSpacing); | 1025 bounds.set_x(bounds.x() + kFirstRunBubbleLeftSpacing); |
1032 | 1026 FirstRunBubble::Show(browser_->profile(), location_icon_image_, bounds); |
1033 FirstRunBubble::Show(browser_->profile(), location_icon_image_, bounds, | |
1034 bubble_type); | |
1035 } | 1027 } |
1036 | 1028 |
1037 gboolean LocationBarViewGtk::OnIconReleased(GtkWidget* sender, | 1029 gboolean LocationBarViewGtk::OnIconReleased(GtkWidget* sender, |
1038 GdkEventButton* event) { | 1030 GdkEventButton* event) { |
1039 WebContents* tab = GetWebContents(); | 1031 WebContents* tab = GetWebContents(); |
1040 | 1032 |
1041 if (event->button == 1) { | 1033 if (event->button == 1) { |
1042 // Do not show page info if the user has been editing the location | 1034 // Do not show page info if the user has been editing the location |
1043 // bar, or the location bar is at the NTP. | 1035 // bar, or the location bar is at the NTP. |
1044 if (location_entry()->IsEditingOrEmpty()) | 1036 if (location_entry()->IsEditingOrEmpty()) |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 std::string badge_text = page_action_->GetBadgeText(tab_id); | 1646 std::string badge_text = page_action_->GetBadgeText(tab_id); |
1655 if (badge_text.empty()) | 1647 if (badge_text.empty()) |
1656 return FALSE; | 1648 return FALSE; |
1657 | 1649 |
1658 gfx::CanvasSkiaPaint canvas(event, false); | 1650 gfx::CanvasSkiaPaint canvas(event, false); |
1659 GtkAllocation allocation; | 1651 GtkAllocation allocation; |
1660 gtk_widget_get_allocation(widget, &allocation); | 1652 gtk_widget_get_allocation(widget, &allocation); |
1661 page_action_->PaintBadge(&canvas, gfx::Rect(allocation), tab_id); | 1653 page_action_->PaintBadge(&canvas, gfx::Rect(allocation), tab_id); |
1662 return FALSE; | 1654 return FALSE; |
1663 } | 1655 } |
OLD | NEW |