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