| 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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
| 32 #include "chrome/browser/ui/browser_finder.h" | 32 #include "chrome/browser/ui/browser_finder.h" |
| 33 #include "chrome/browser/ui/browser_instant_controller.h" | 33 #include "chrome/browser/ui/browser_instant_controller.h" |
| 34 #include "chrome/browser/ui/browser_window.h" | 34 #include "chrome/browser/ui/browser_window.h" |
| 35 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 35 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 36 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 36 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 37 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 38 #include "chrome/browser/ui/view_ids.h" | 38 #include "chrome/browser/ui/view_ids.h" |
| 39 #include "chrome/browser/ui/views/browser_dialogs.h" | 39 #include "chrome/browser/ui/views/browser_dialogs.h" |
| 40 #include "chrome/browser/ui/views/layout_constants.h" | 40 #include "chrome/browser/ui/views/layout_constants.h" |
| 41 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
| 41 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" | 42 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
| 42 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" | 43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
| 43 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 44 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" | 45 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" |
| 45 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 46 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 46 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" | 47 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" |
| 47 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 48 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 48 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 49 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
| 49 #include "chrome/browser/ui/views/location_bar/save_credit_card_icon_view.h" | 50 #include "chrome/browser/ui/views/location_bar/save_credit_card_icon_view.h" |
| 50 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 51 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 return base::i18n::IsRTL() ? 1 : 0; | 110 return base::i18n::IsRTL() ? 1 : 0; |
| 110 } | 111 } |
| 111 | 112 |
| 112 } // namespace | 113 } // namespace |
| 113 | 114 |
| 114 | 115 |
| 115 // LocationBarView ----------------------------------------------------------- | 116 // LocationBarView ----------------------------------------------------------- |
| 116 | 117 |
| 117 // static | 118 // static |
| 118 | 119 |
| 119 // TODO(jonross): Replace with lookup once Material Design asset has landed. | 120 // Thickness of the edges of the omnibox background images, for popup windows. |
| 120 // (https://crbug.com/495654) | |
| 121 // Thickness of the edges of the omnibox background images, for normal and | |
| 122 // popup windows. | |
| 123 const int kNormalEdgeThickness = 2; | |
| 124 const int kPopupEdgeThickness = 1; | 121 const int kPopupEdgeThickness = 1; |
| 125 | 122 |
| 126 const char LocationBarView::kViewClassName[] = "LocationBarView"; | 123 const char LocationBarView::kViewClassName[] = "LocationBarView"; |
| 127 | 124 |
| 128 LocationBarView::LocationBarView(Browser* browser, | 125 LocationBarView::LocationBarView(Browser* browser, |
| 129 Profile* profile, | 126 Profile* profile, |
| 130 CommandUpdater* command_updater, | 127 CommandUpdater* command_updater, |
| 131 Delegate* delegate, | 128 Delegate* delegate, |
| 132 bool is_popup_mode) | 129 bool is_popup_mode) |
| 133 : LocationBar(profile), | 130 : LocationBar(profile), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 157 edit_bookmarks_enabled_.Init( | 154 edit_bookmarks_enabled_.Init( |
| 158 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), | 155 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), |
| 159 base::Bind(&LocationBarView::UpdateWithoutTabRestore, | 156 base::Bind(&LocationBarView::UpdateWithoutTabRestore, |
| 160 base::Unretained(this))); | 157 base::Unretained(this))); |
| 161 | 158 |
| 162 if (browser_) | 159 if (browser_) |
| 163 browser_->search_model()->AddObserver(this); | 160 browser_->search_model()->AddObserver(this); |
| 164 | 161 |
| 165 ui_zoom::ZoomEventManager::GetForBrowserContext(profile) | 162 ui_zoom::ZoomEventManager::GetForBrowserContext(profile) |
| 166 ->AddZoomEventManagerObserver(this); | 163 ->AddZoomEventManagerObserver(this); |
| 164 |
| 165 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 166 set_background(new BackgroundWith1PxBorder( |
| 167 GetColor(SecurityStateModel::NONE, BACKGROUND), |
| 168 SkColorSetARGB(0x4D, 0x00, 0x00, 0x00), is_popup_mode_)); |
| 169 } |
| 167 } | 170 } |
| 168 | 171 |
| 169 LocationBarView::~LocationBarView() { | 172 LocationBarView::~LocationBarView() { |
| 170 if (template_url_service_) | 173 if (template_url_service_) |
| 171 template_url_service_->RemoveObserver(this); | 174 template_url_service_->RemoveObserver(this); |
| 172 if (browser_) | 175 if (browser_) |
| 173 browser_->search_model()->RemoveObserver(this); | 176 browser_->search_model()->RemoveObserver(this); |
| 174 | 177 |
| 175 ui_zoom::ZoomEventManager::GetForBrowserContext(profile()) | 178 ui_zoom::ZoomEventManager::GetForBrowserContext(profile()) |
| 176 ->RemoveZoomEventManagerObserver(this); | 179 ->RemoveZoomEventManagerObserver(this); |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 gfx::Point* top_left_screen_coord, | 509 gfx::Point* top_left_screen_coord, |
| 507 int* popup_width, | 510 int* popup_width, |
| 508 int* left_margin, | 511 int* left_margin, |
| 509 int* right_margin, | 512 int* right_margin, |
| 510 int top_edge_overlap) { | 513 int top_edge_overlap) { |
| 511 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap); | 514 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap); |
| 512 views::View::ConvertPointToScreen(parent(), top_left_screen_coord); | 515 views::View::ConvertPointToScreen(parent(), top_left_screen_coord); |
| 513 | 516 |
| 514 *popup_width = parent()->width(); | 517 *popup_width = parent()->width(); |
| 515 gfx::Rect location_bar_bounds(bounds()); | 518 gfx::Rect location_bar_bounds(bounds()); |
| 516 location_bar_bounds.Inset(kNormalEdgeThickness, 0); | 519 location_bar_bounds.Inset(GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS), |
| 520 0); |
| 517 *left_margin = location_bar_bounds.x(); | 521 *left_margin = location_bar_bounds.x(); |
| 518 *right_margin = *popup_width - location_bar_bounds.right(); | 522 *right_margin = *popup_width - location_bar_bounds.right(); |
| 519 } | 523 } |
| 520 | 524 |
| 521 //////////////////////////////////////////////////////////////////////////////// | 525 //////////////////////////////////////////////////////////////////////////////// |
| 522 // LocationBarView, public LocationBar implementation: | 526 // LocationBarView, public LocationBar implementation: |
| 523 | 527 |
| 524 void LocationBarView::FocusLocation(bool select_all) { | 528 void LocationBarView::FocusLocation(bool select_all) { |
| 525 omnibox_view_->SetFocus(); | 529 omnibox_view_->SetFocus(); |
| 526 if (select_all) | 530 if (select_all) |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 } | 882 } |
| 879 | 883 |
| 880 int LocationBarView::GetHorizontalEdgeThickness() const { | 884 int LocationBarView::GetHorizontalEdgeThickness() const { |
| 881 // In maximized popup mode, there isn't any edge. | 885 // In maximized popup mode, there isn't any edge. |
| 882 return (is_popup_mode_ && browser_ && browser_->window() && | 886 return (is_popup_mode_ && browser_ && browser_->window() && |
| 883 browser_->window()->IsMaximized()) ? | 887 browser_->window()->IsMaximized()) ? |
| 884 0 : GetVerticalEdgeThickness(); | 888 0 : GetVerticalEdgeThickness(); |
| 885 } | 889 } |
| 886 | 890 |
| 887 int LocationBarView::GetVerticalEdgeThickness() const { | 891 int LocationBarView::GetVerticalEdgeThickness() const { |
| 888 // In Material Design vertical layout disregards the border. | 892 return is_popup_mode_ ? kPopupEdgeThickness |
| 889 if (ui::MaterialDesignController::IsModeMaterial()) | 893 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS); |
| 890 return 0; | |
| 891 return is_popup_mode_ ? kPopupEdgeThickness : kNormalEdgeThickness; | |
| 892 } | 894 } |
| 893 | 895 |
| 894 int LocationBarView::VerticalPadding() const { | 896 int LocationBarView::VerticalPadding() const { |
| 895 return is_popup_mode_ ? | 897 return is_popup_mode_ ? |
| 896 kPopupEdgeThickness : GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); | 898 kPopupEdgeThickness : GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); |
| 897 } | 899 } |
| 898 | 900 |
| 899 bool LocationBarView::RefreshContentSettingViews() { | 901 bool LocationBarView::RefreshContentSettingViews() { |
| 900 bool visibility_changed = false; | 902 bool visibility_changed = false; |
| 901 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 903 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 | 1284 |
| 1283 void LocationBarView::OnFocus() { | 1285 void LocationBarView::OnFocus() { |
| 1284 // Explicitly focus the omnibox so a focus ring will be displayed around it on | 1286 // Explicitly focus the omnibox so a focus ring will be displayed around it on |
| 1285 // Windows. | 1287 // Windows. |
| 1286 omnibox_view_->SetFocus(); | 1288 omnibox_view_->SetFocus(); |
| 1287 } | 1289 } |
| 1288 | 1290 |
| 1289 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 1291 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
| 1290 View::OnPaint(canvas); | 1292 View::OnPaint(canvas); |
| 1291 | 1293 |
| 1294 if (ui::MaterialDesignController::IsModeMaterial()) |
| 1295 return; // The background and border are painted by our Background. |
| 1296 |
| 1292 // Fill the location bar background color behind the border. Parts of the | 1297 // Fill the location bar background color behind the border. Parts of the |
| 1293 // border images are meant to rest atop the toolbar background and parts atop | 1298 // border images are meant to rest atop the toolbar background and parts atop |
| 1294 // the omnibox background, so we can't just blindly fill our entire bounds. | 1299 // the omnibox background, so we can't just blindly fill our entire bounds. |
| 1295 gfx::Rect bounds(GetContentsBounds()); | 1300 gfx::Rect bounds(GetContentsBounds()); |
| 1296 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); | 1301 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); |
| 1297 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND)); | 1302 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND)); |
| 1298 if (is_popup_mode_) { | 1303 if (is_popup_mode_) { |
| 1299 canvas->FillRect(bounds, color); | 1304 canvas->FillRect(bounds, color); |
| 1300 } else { | 1305 } else { |
| 1301 SkPaint paint; | 1306 SkPaint paint; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1314 | 1319 |
| 1315 ui::PaintRecorder recorder(context, size()); | 1320 ui::PaintRecorder recorder(context, size()); |
| 1316 | 1321 |
| 1317 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need | 1322 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need |
| 1318 // the focus rect to appear on top of children we paint here rather than | 1323 // the focus rect to appear on top of children we paint here rather than |
| 1319 // OnPaint(). | 1324 // OnPaint(). |
| 1320 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. | 1325 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. |
| 1321 if (show_focus_rect_ && HasFocus()) | 1326 if (show_focus_rect_ && HasFocus()) |
| 1322 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); | 1327 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); |
| 1323 | 1328 |
| 1329 if (ui::MaterialDesignController::IsModeMaterial()) |
| 1330 return; // The background and border are painted by our Background. |
| 1331 |
| 1324 // Maximized popup windows don't draw the horizontal edges. We implement this | 1332 // Maximized popup windows don't draw the horizontal edges. We implement this |
| 1325 // by simply expanding the paint area outside the view by the edge thickness. | 1333 // by simply expanding the paint area outside the view by the edge thickness. |
| 1326 gfx::Rect border_rect(GetContentsBounds()); | 1334 gfx::Rect border_rect(GetContentsBounds()); |
| 1327 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) | 1335 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) |
| 1328 border_rect.Inset(-kPopupEdgeThickness, 0); | 1336 border_rect.Inset(-kPopupEdgeThickness, 0); |
| 1329 | 1337 |
| 1330 if (ui::MaterialDesignController::IsModeMaterial()) { | 1338 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), |
| 1331 gfx::Canvas* canvas = recorder.canvas(); | 1339 border_rect); |
| 1332 gfx::ScopedCanvas scoped_canvas(canvas); | |
| 1333 const float scale = canvas->UndoDeviceScaleFactor(); | |
| 1334 | |
| 1335 SkPaint paint; | |
| 1336 paint.setStyle(SkPaint::Style::kStroke_Style); | |
| 1337 paint.setColor(SkColorSetARGB(0x40, 0x00, 0x00, 0x00)); | |
| 1338 paint.setStrokeWidth(1); | |
| 1339 paint.setAntiAlias(true); | |
| 1340 | |
| 1341 const float kOffset = 0.5f; | |
| 1342 gfx::RectF border_rect_f(border_rect); | |
| 1343 border_rect_f.Scale(scale); | |
| 1344 gfx::InsetsF insets(kOffset, kOffset, kOffset, kOffset); | |
| 1345 border_rect_f.Inset(insets); | |
| 1346 | |
| 1347 const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * scale); | |
| 1348 canvas->sk_canvas()->drawRoundRect(gfx::RectFToSkRect(border_rect_f), | |
| 1349 kCornerRadius, kCornerRadius, paint); | |
| 1350 } else { | |
| 1351 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), | |
| 1352 border_rect); | |
| 1353 } | |
| 1354 } | 1340 } |
| 1355 | 1341 |
| 1356 //////////////////////////////////////////////////////////////////////////////// | 1342 //////////////////////////////////////////////////////////////////////////////// |
| 1357 // LocationBarView, private views::ButtonListener implementation: | 1343 // LocationBarView, private views::ButtonListener implementation: |
| 1358 | 1344 |
| 1359 void LocationBarView::ButtonPressed(views::Button* sender, | 1345 void LocationBarView::ButtonPressed(views::Button* sender, |
| 1360 const ui::Event& event) { | 1346 const ui::Event& event) { |
| 1361 DCHECK_EQ(mic_search_view_, sender); | 1347 DCHECK_EQ(mic_search_view_, sender); |
| 1362 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); | 1348 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); |
| 1363 } | 1349 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 | 1443 |
| 1458 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1444 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
| 1459 const SearchModel::State& new_state) { | 1445 const SearchModel::State& new_state) { |
| 1460 const bool visible = !GetToolbarModel()->input_in_progress() && | 1446 const bool visible = !GetToolbarModel()->input_in_progress() && |
| 1461 new_state.voice_search_supported; | 1447 new_state.voice_search_supported; |
| 1462 if (mic_search_view_->visible() != visible) { | 1448 if (mic_search_view_->visible() != visible) { |
| 1463 mic_search_view_->SetVisible(visible); | 1449 mic_search_view_->SetVisible(visible); |
| 1464 Layout(); | 1450 Layout(); |
| 1465 } | 1451 } |
| 1466 } | 1452 } |
| OLD | NEW |