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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 #endif | 139 #endif |
140 | 140 |
141 if (((*font_y_offset >= 0) && | 141 if (((*font_y_offset >= 0) && |
142 ((*font_y_offset + font->GetHeight()) <= height)) || | 142 ((*font_y_offset + font->GetHeight()) <= height)) || |
143 (font->GetFontSize() <= 1)) | 143 (font->GetFontSize() <= 1)) |
144 return; | 144 return; |
145 *font = font->DeriveFont(-1); | 145 *font = font->DeriveFont(-1); |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
| 149 // Height of the location bar's round corner region. |
| 150 const int kBorderRoundCornerHeight = 5; |
| 151 // Width of location bar's round corner region. |
| 152 const int kBorderRoundCornerWidth = 4; |
| 153 // Radius of the round corners inside the location bar. |
| 154 const int kBorderCornerRadius = 2; |
| 155 |
149 } // namespace | 156 } // namespace |
150 | 157 |
151 | 158 |
152 // LocationBarView ----------------------------------------------------------- | 159 // LocationBarView ----------------------------------------------------------- |
153 | 160 |
154 // static | 161 // static |
155 const int LocationBarView::kNormalEdgeThickness = 2; | 162 const int LocationBarView::kNormalHorizontalEdgeThickness = 2; |
156 const int LocationBarView::kPopupEdgeThickness = 1; | 163 const int LocationBarView::kPopupEdgeThickness = 1; |
| 164 const int LocationBarView::kNormalVerticalEdgeThickness = 3; |
157 const int LocationBarView::kIconInternalPadding = 2; | 165 const int LocationBarView::kIconInternalPadding = 2; |
158 const int LocationBarView::kBubblePadding = 1; | 166 const int LocationBarView::kBubblePadding = 1; |
159 const char LocationBarView::kViewClassName[] = "LocationBarView"; | 167 const char LocationBarView::kViewClassName[] = "LocationBarView"; |
160 | 168 |
161 LocationBarView::LocationBarView(Browser* browser, | 169 LocationBarView::LocationBarView(Browser* browser, |
162 Profile* profile, | 170 Profile* profile, |
163 CommandUpdater* command_updater, | 171 CommandUpdater* command_updater, |
164 ToolbarModel* model, | 172 ToolbarModel* model, |
165 Delegate* delegate, | 173 Delegate* delegate, |
166 bool is_popup_mode) | 174 bool is_popup_mode) |
(...skipping 20 matching lines...) Expand all Loading... |
187 script_bubble_icon_view_(NULL), | 195 script_bubble_icon_view_(NULL), |
188 star_view_(NULL), | 196 star_view_(NULL), |
189 action_box_button_view_(NULL), | 197 action_box_button_view_(NULL), |
190 is_popup_mode_(is_popup_mode), | 198 is_popup_mode_(is_popup_mode), |
191 show_focus_rect_(false), | 199 show_focus_rect_(false), |
192 template_url_service_(NULL), | 200 template_url_service_(NULL), |
193 animation_offset_(0) { | 201 animation_offset_(0) { |
194 if (!views::Textfield::IsViewsTextfieldEnabled()) | 202 if (!views::Textfield::IsViewsTextfieldEnabled()) |
195 set_id(VIEW_ID_OMNIBOX); | 203 set_id(VIEW_ID_OMNIBOX); |
196 | 204 |
197 const int kOmniboxBorderImages[] = IMAGE_GRID(IDR_OMNIBOX_BORDER); | 205 const int kOmniboxPopupImages[] = { |
198 const int kOmniboxPopupImages[] = IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER); | 206 IDR_OMNIBOX_POPUP_BORDER_EDGE, |
199 background_border_painter_.reset( | 207 IDR_OMNIBOX_POPUP_BORDER_CENTER, |
200 views::Painter::CreateImageGridPainter( | 208 IDR_OMNIBOX_POPUP_BORDER_EDGE, |
201 is_popup_mode_ ? kOmniboxPopupImages : kOmniboxBorderImages)); | 209 }; |
202 #if defined(OS_CHROMEOS) | 210 background_painter_.reset( |
203 if (!is_popup_mode_) { | 211 is_popup_mode_ ? |
204 const int kOmniboxFillingImages[] = IMAGE_GRID(IDR_OMNIBOX_FILLING); | 212 new views::HorizontalPainter(kOmniboxPopupImages) : |
205 background_filling_painter_.reset( | 213 views::Painter::CreateImagePainter( |
206 views::Painter::CreateImageGridPainter(kOmniboxFillingImages)); | 214 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
207 } | 215 IDR_OMNIBOX_BORDER).ToImageSkia(), |
208 #endif | 216 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth, |
| 217 kBorderRoundCornerHeight, kBorderRoundCornerWidth))); |
209 | 218 |
210 edit_bookmarks_enabled_.Init( | 219 edit_bookmarks_enabled_.Init( |
211 prefs::kEditBookmarksEnabled, | 220 prefs::kEditBookmarksEnabled, |
212 profile_->GetPrefs(), | 221 profile_->GetPrefs(), |
213 base::Bind(&LocationBarView::Update, | 222 base::Bind(&LocationBarView::Update, |
214 base::Unretained(this), | 223 base::Unretained(this), |
215 static_cast<content::WebContents*>(NULL))); | 224 static_cast<content::WebContents*>(NULL))); |
216 | 225 |
217 if (browser_) | 226 if (browser_) |
218 browser_->toolbar_model()->SetSupportsExtractionOfURLLikeSearchTerms(true); | 227 browser_->toolbar_model()->SetSupportsExtractionOfURLLikeSearchTerms(true); |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 else | 677 else |
669 set_focusable(focusable); | 678 set_focusable(focusable); |
670 } | 679 } |
671 | 680 |
672 bool LocationBarView::IsLocationEntryFocusableInRootView() const { | 681 bool LocationBarView::IsLocationEntryFocusableInRootView() const { |
673 OmniboxViewViews* omnibox_views = GetOmniboxViewViews(location_entry_.get()); | 682 OmniboxViewViews* omnibox_views = GetOmniboxViewViews(location_entry_.get()); |
674 return omnibox_views ? omnibox_views->IsFocusable() : View::IsFocusable(); | 683 return omnibox_views ? omnibox_views->IsFocusable() : View::IsFocusable(); |
675 } | 684 } |
676 | 685 |
677 gfx::Size LocationBarView::GetPreferredSize() { | 686 gfx::Size LocationBarView::GetPreferredSize() { |
678 return background_border_painter_->GetMinimumSize(); | 687 return background_painter_->GetMinimumSize(); |
679 } | 688 } |
680 | 689 |
681 void LocationBarView::Layout() { | 690 void LocationBarView::Layout() { |
682 if (!location_entry_.get()) | 691 if (!location_entry_.get()) |
683 return; | 692 return; |
684 | 693 |
685 // TODO(jhawkins): Remove once crbug.com/101994 is fixed. | 694 // TODO(jhawkins): Remove once crbug.com/101994 is fixed. |
686 CHECK(location_icon_view_); | 695 CHECK(location_icon_view_); |
687 | 696 |
688 selected_keyword_view_->SetVisible(false); | 697 selected_keyword_view_->SetVisible(false); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 std::min(width, entry_width), | 934 std::min(width, entry_width), |
926 ime_inline_autocomplete_view_->GetPreferredSize().height()); | 935 ime_inline_autocomplete_view_->GetPreferredSize().height()); |
927 } | 936 } |
928 | 937 |
929 location_entry_view_->SetBoundsRect(location_bounds); | 938 location_entry_view_->SetBoundsRect(location_bounds); |
930 } | 939 } |
931 | 940 |
932 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 941 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
933 View::OnPaint(canvas); | 942 View::OnPaint(canvas); |
934 | 943 |
935 // Fill the location bar background color behind the border. Parts of the | |
936 // border images are meant to rest atop the toolbar background and parts atop | |
937 // the omnibox background, so we can't just blindly fill our entire bounds. | |
938 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); | |
939 if (!background_filling_painter_) { | |
940 gfx::Rect bounds(GetContentsBounds()); | |
941 bounds.Inset(horizontal_edge_thickness, vertical_edge_thickness()); | |
942 SkColor color(GetColor(ToolbarModel::NONE, BACKGROUND)); | |
943 if (is_popup_mode_) { | |
944 canvas->FillRect(bounds, color); | |
945 } else { | |
946 SkPaint paint; | |
947 paint.setStyle(SkPaint::kFill_Style); | |
948 paint.setColor(color); | |
949 const int kBorderCornerRadius = 2; | |
950 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | |
951 } | |
952 } | |
953 | |
954 // Maximized popup windows don't draw the horizontal edges. We implement this | 944 // Maximized popup windows don't draw the horizontal edges. We implement this |
955 // by simply expanding the paint area outside the view by the edge thickness. | 945 // by simply expanding the paint area outside the view by the edge thickness. |
| 946 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
956 gfx::Rect background_rect(GetContentsBounds()); | 947 gfx::Rect background_rect(GetContentsBounds()); |
957 if (is_popup_mode_ && (horizontal_edge_thickness == 0)) | 948 if (is_popup_mode_ && (horizontal_edge_thickness == 0)) |
958 background_rect.Inset(-kPopupEdgeThickness, 0); | 949 background_rect.Inset(-kPopupEdgeThickness, 0); |
959 views::Painter::PaintPainterAt(canvas, background_border_painter_.get(), | 950 views::Painter::PaintPainterAt(canvas, background_painter_.get(), |
960 background_rect); | 951 background_rect); |
961 if (background_filling_painter_) | |
962 background_filling_painter_->Paint(canvas, size()); | |
963 | 952 |
964 if (!is_popup_mode_) | 953 // Draw the background color so that the graphical elements at the edges |
| 954 // appear over the correct color. (The edit draws its own background, so this |
| 955 // isn't important for that.) |
| 956 // TODO(pkasting): We need images that are transparent in the middle, so we |
| 957 // can draw the border images over the background color instead of the |
| 958 // reverse; this antialiases better (see comments in |
| 959 // OmniboxPopupContentsView::OnPaint()). |
| 960 gfx::Rect bounds(GetContentsBounds()); |
| 961 bounds.Inset(horizontal_edge_thickness, vertical_edge_thickness()); |
| 962 SkColor color(GetColor(ToolbarModel::NONE, BACKGROUND)); |
| 963 if (is_popup_mode_) { |
| 964 canvas->FillRect(bounds, color); |
| 965 } else { |
| 966 SkPaint paint; |
| 967 paint.setStyle(SkPaint::kFill_Style); |
| 968 paint.setAntiAlias(true); |
| 969 // TODO(jamescook): Make the corners of the dropdown match the corners of |
| 970 // the omnibox. |
| 971 // Paint the actual background color. |
| 972 paint.setColor(color); |
| 973 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
965 PaintPageActionBackgrounds(canvas); | 974 PaintPageActionBackgrounds(canvas); |
| 975 } |
966 | 976 |
967 // For non-InstantExtendedAPI cases, if necessary, show focus rect. | 977 // For non-InstantExtendedAPI cases, if necessary, show focus rect. |
968 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. | 978 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. |
969 if (show_focus_rect_ && HasFocus()) { | 979 if (show_focus_rect_ && HasFocus()) { |
970 gfx::Rect r = location_entry_view_->bounds(); | 980 gfx::Rect r = location_entry_view_->bounds(); |
971 // TODO(jamescook): Is this still needed? | 981 // TODO(jamescook): Is this still needed? |
972 r.Inset(-1, 0); | 982 r.Inset(-1, 0); |
973 #if defined(OS_WIN) | 983 #if defined(OS_WIN) |
974 r.Inset(0, -1); | 984 r.Inset(0, -1); |
975 #endif | 985 #endif |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 | 1118 |
1109 InstantController* LocationBarView::GetInstant() { | 1119 InstantController* LocationBarView::GetInstant() { |
1110 return delegate_->GetInstant(); | 1120 return delegate_->GetInstant(); |
1111 } | 1121 } |
1112 | 1122 |
1113 WebContents* LocationBarView::GetWebContents() const { | 1123 WebContents* LocationBarView::GetWebContents() const { |
1114 return delegate_->GetWebContents(); | 1124 return delegate_->GetWebContents(); |
1115 } | 1125 } |
1116 | 1126 |
1117 int LocationBarView::GetHorizontalEdgeThickness() const { | 1127 int LocationBarView::GetHorizontalEdgeThickness() const { |
| 1128 if (!is_popup_mode_) |
| 1129 return kNormalHorizontalEdgeThickness; |
| 1130 |
1118 // In maximized popup mode, there isn't any edge. | 1131 // In maximized popup mode, there isn't any edge. |
1119 return (is_popup_mode_ && browser_ && browser_->window() && | 1132 return (browser_ && browser_->window() && browser_->window()->IsMaximized()) ? |
1120 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); | 1133 0 : kPopupEdgeThickness; |
1121 } | 1134 } |
1122 | 1135 |
1123 void LocationBarView::RefreshContentSettingViews() { | 1136 void LocationBarView::RefreshContentSettingViews() { |
1124 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 1137 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
1125 i != content_setting_views_.end(); ++i) { | 1138 i != content_setting_views_.end(); ++i) { |
1126 (*i)->Update(model_->GetInputInProgress() ? NULL : GetWebContents()); | 1139 (*i)->Update(model_->GetInputInProgress() ? NULL : GetWebContents()); |
1127 } | 1140 } |
1128 } | 1141 } |
1129 | 1142 |
1130 void LocationBarView::DeletePageActionViews() { | 1143 void LocationBarView::DeletePageActionViews() { |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1533 int LocationBarView::GetInternalHeight(bool use_preferred_size) { | 1546 int LocationBarView::GetInternalHeight(bool use_preferred_size) { |
1534 int total_height = | 1547 int total_height = |
1535 use_preferred_size ? GetPreferredSize().height() : height(); | 1548 use_preferred_size ? GetPreferredSize().height() : height(); |
1536 return std::max(total_height - (vertical_edge_thickness() * 2), 0); | 1549 return std::max(total_height - (vertical_edge_thickness() * 2), 0); |
1537 } | 1550 } |
1538 | 1551 |
1539 bool LocationBarView::HasValidSuggestText() const { | 1552 bool LocationBarView::HasValidSuggestText() const { |
1540 return suggested_text_view_->visible() && | 1553 return suggested_text_view_->visible() && |
1541 !suggested_text_view_->size().IsEmpty(); | 1554 !suggested_text_view_->size().IsEmpty(); |
1542 } | 1555 } |
OLD | NEW |