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/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 #include "ui/gfx/canvas.h" | 70 #include "ui/gfx/canvas.h" |
71 #include "ui/gfx/color_utils.h" | 71 #include "ui/gfx/color_utils.h" |
72 #include "ui/gfx/image/image.h" | 72 #include "ui/gfx/image/image.h" |
73 #include "ui/gfx/skia_util.h" | 73 #include "ui/gfx/skia_util.h" |
74 #include "ui/views/border.h" | 74 #include "ui/views/border.h" |
75 #include "ui/views/button_drag_utils.h" | 75 #include "ui/views/button_drag_utils.h" |
76 #include "ui/views/controls/label.h" | 76 #include "ui/views/controls/label.h" |
77 #include "ui/views/widget/widget.h" | 77 #include "ui/views/widget/widget.h" |
78 | 78 |
79 #if defined(OS_WIN) && !defined(USE_AURA) | 79 #if defined(OS_WIN) && !defined(USE_AURA) |
| 80 #include "base/win/metro.h" |
80 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" | 81 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
81 #endif | 82 #endif |
82 | 83 |
83 #if !defined(OS_CHROMEOS) | 84 #if !defined(OS_CHROMEOS) |
84 #include "chrome/browser/ui/views/first_run_bubble.h" | 85 #include "chrome/browser/ui/views/first_run_bubble.h" |
85 #endif | 86 #endif |
86 | 87 |
87 #if defined(USE_AURA) | 88 #if defined(USE_AURA) |
88 #include "ui/compositor/layer.h" | 89 #include "ui/compositor/layer.h" |
89 #include "ui/compositor/scoped_layer_animation_settings.h" | 90 #include "ui/compositor/scoped_layer_animation_settings.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 239 |
239 ev_bubble_view_ = | 240 ev_bubble_view_ = |
240 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, | 241 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, |
241 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this); | 242 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this); |
242 AddChildView(ev_bubble_view_); | 243 AddChildView(ev_bubble_view_); |
243 ev_bubble_view_->SetVisible(false); | 244 ev_bubble_view_->SetVisible(false); |
244 ev_bubble_view_->set_drag_controller(this); | 245 ev_bubble_view_->set_drag_controller(this); |
245 | 246 |
246 // URL edit field. | 247 // URL edit field. |
247 // View container for URL edit field. | 248 // View container for URL edit field. |
| 249 OmniboxWindowMode omnibox_window_mode = |
| 250 (mode_ == POPUP) ? OMNIBOX_WINDOW_MODE_POPUP : |
| 251 (mode_ == METRO_SNAP) ? OMNIBOX_WINDOW_MODE_DISABLED : |
| 252 OMNIBOX_WINDOW_MODE_NORMAL; |
| 253 |
248 location_entry_.reset(CreateOmniboxView(this, model_, profile_, | 254 location_entry_.reset(CreateOmniboxView(this, model_, profile_, |
249 command_updater_, mode_ == POPUP, this, popup_parent_view)); | 255 command_updater_, omnibox_window_mode, this, popup_parent_view)); |
250 SetLocationEntryFocusable(true); | 256 SetLocationEntryFocusable(true); |
251 | 257 |
252 location_entry_view_ = location_entry_->AddToView(this); | 258 location_entry_view_ = location_entry_->AddToView(this); |
253 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE); | 259 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE); |
254 | 260 |
255 selected_keyword_view_ = new SelectedKeywordView( | 261 selected_keyword_view_ = new SelectedKeywordView( |
256 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, | 262 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, |
257 GetColor(ToolbarModel::NONE, TEXT), profile_); | 263 GetColor(ToolbarModel::NONE, TEXT), profile_); |
258 AddChildView(selected_keyword_view_); | 264 AddChildView(selected_keyword_view_); |
259 selected_keyword_view_->SetFont(font_); | 265 selected_keyword_view_->SetFont(font_); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 return omnibox_views->IsLocationEntryFocusableInRootView(); | 586 return omnibox_views->IsLocationEntryFocusableInRootView(); |
581 return view_to_focus_->IsFocusable(); | 587 return view_to_focus_->IsFocusable(); |
582 } | 588 } |
583 | 589 |
584 gfx::Size LocationBarView::GetPreferredSize() { | 590 gfx::Size LocationBarView::GetPreferredSize() { |
585 if (search_model_ && search_model_->mode().is_ntp()) | 591 if (search_model_ && search_model_->mode().is_ntp()) |
586 return gfx::Size(0, chrome::search::GetNTPOmniboxHeight( | 592 return gfx::Size(0, chrome::search::GetNTPOmniboxHeight( |
587 location_entry_->GetFont())); | 593 location_entry_->GetFont())); |
588 int delta = chrome::search::IsInstantExtendedAPIEnabled(profile_) ? | 594 int delta = chrome::search::IsInstantExtendedAPIEnabled(profile_) ? |
589 kSearchEditHeightPadding : 0; | 595 kSearchEditHeightPadding : 0; |
590 return gfx::Size(0, GetThemeProvider()->GetImageSkiaNamed(mode_ == POPUP ? | 596 |
591 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height() + delta); | 597 int image_id = (mode_ == POPUP || mode_ == METRO_SNAP) ? |
| 598 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C; |
| 599 return gfx::Size( |
| 600 0, |
| 601 GetThemeProvider()->GetImageSkiaNamed(image_id)->height() + delta); |
592 } | 602 } |
593 | 603 |
594 void LocationBarView::Layout() { | 604 void LocationBarView::Layout() { |
595 if (!location_entry_.get()) | 605 if (!location_entry_.get()) |
596 return; | 606 return; |
597 | 607 |
598 // TODO(jhawkins): Remove once crbug.com/101994 is fixed. | 608 // TODO(jhawkins): Remove once crbug.com/101994 is fixed. |
599 CHECK(location_icon_view_); | 609 CHECK(location_icon_view_); |
600 | 610 |
601 // TODO(sky): baseline layout. | 611 // TODO(sky): baseline layout. |
602 int location_y = kVerticalEdgeThickness; | 612 int location_y = kVerticalEdgeThickness; |
603 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 613 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want |
604 // to position our child views in this case, because other things may be | 614 // to position our child views in this case, because other things may be |
605 // positioned relative to them (e.g. the "bookmark added" bubble if the user | 615 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
606 // hits ctrl-d). | 616 // hits ctrl-d). |
607 int location_height = GetInternalHeight(false); | 617 int location_height = GetInternalHeight(false); |
608 | 618 |
609 // In NTP mode, hide all location bar decorations. | 619 // In NTP mode, hide all location bar decorations. |
610 if (search_model_ && search_model_->mode().is_ntp()) { | 620 if (search_model_ && search_model_->mode().is_ntp()) { |
611 gfx::Rect location_bounds(0, location_y, width(), location_height); | 621 gfx::Rect location_bounds(0, location_y, width(), location_height); |
612 location_entry_view_->SetBoundsRect(location_bounds); | 622 location_entry_view_->SetBoundsRect(location_bounds); |
613 for (int i = 0; i < child_count(); ++i) | 623 for (int i = 0; i < child_count(); ++i) |
614 if (child_at(i) != location_entry_view_) | 624 if (child_at(i) != location_entry_view_) |
615 child_at(i)->SetVisible(false); | 625 child_at(i)->SetVisible(false); |
616 return; | 626 return; |
617 } | 627 } |
618 | 628 |
619 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the | 629 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the |
620 // omnibox' parent, so there isn't any edge to account for at all. | 630 // omnibox' parent, so there isn't any edge to account for at all. |
621 const int kEdgeThickness = (mode_ == NORMAL) ? | 631 const int kEdgeThickness = (mode_ == NORMAL || mode_ == METRO_SNAP) ? |
622 kNormalHorizontalEdgeThickness : 0; | 632 kNormalHorizontalEdgeThickness : 0; |
623 // The edit has 1 px of horizontal whitespace inside it before the text. | 633 // The edit has 1 px of horizontal whitespace inside it before the text. |
624 const int kEditInternalSpace = 1; | 634 const int kEditInternalSpace = 1; |
625 // The space between an item and the edit is the normal item space, minus the | 635 // The space between an item and the edit is the normal item space, minus the |
626 // edit's built-in space (so the apparent space will be the same). | 636 // edit's built-in space (so the apparent space will be the same). |
627 const int kItemEditPadding = GetItemPadding() - kEditInternalSpace; | 637 const int kItemEditPadding = GetItemPadding() - kEditInternalSpace; |
628 const int kEdgeEditPadding = GetEdgeItemPadding() - kEditInternalSpace; | 638 const int kEdgeEditPadding = GetEdgeItemPadding() - kEditInternalSpace; |
629 const int kBubbleVerticalPadding = (mode_ == POPUP) ? | 639 const int kBubbleVerticalPadding = (mode_ == POPUP) ? |
630 -1 : kBubbleHorizontalPadding; | 640 -1 : kBubbleHorizontalPadding; |
631 | 641 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 } | 880 } |
871 | 881 |
872 location_entry_view_->SetBoundsRect(location_bounds); | 882 location_entry_view_->SetBoundsRect(location_bounds); |
873 } | 883 } |
874 | 884 |
875 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 885 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
876 View::OnPaint(canvas); | 886 View::OnPaint(canvas); |
877 | 887 |
878 if (painter_.get()) { | 888 if (painter_.get()) { |
879 painter_->Paint(canvas, size()); | 889 painter_->Paint(canvas, size()); |
880 } else if (mode_ == POPUP) { | 890 } else if (mode_ == POPUP || mode_ == METRO_SNAP) { |
881 canvas->TileImageInt(*GetThemeProvider()->GetImageSkiaNamed( | 891 canvas->TileImageInt(*GetThemeProvider()->GetImageSkiaNamed( |
882 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height()); | 892 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height()); |
883 } | 893 } |
884 // When used in the app launcher, don't draw a border, the LocationBarView has | 894 // When used in the app launcher, don't draw a border, the LocationBarView has |
885 // its own views::Border. | 895 // its own views::Border. |
886 | 896 |
887 // Draw the background color so that the graphical elements at the edges | 897 // Draw the background color so that the graphical elements at the edges |
888 // appear over the correct color. (The edit draws its own background, so this | 898 // appear over the correct color. (The edit draws its own background, so this |
889 // isn't important for that.) | 899 // isn't important for that.) |
890 // TODO(pkasting): We need images that are transparent in the middle, so we | 900 // TODO(pkasting): We need images that are transparent in the middle, so we |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 1174 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
1165 content::Source<ExtensionAction>(action), | 1175 content::Source<ExtensionAction>(action), |
1166 content::Details<WebContents>(contents)); | 1176 content::Details<WebContents>(contents)); |
1167 } | 1177 } |
1168 } | 1178 } |
1169 } | 1179 } |
1170 } | 1180 } |
1171 | 1181 |
1172 #if defined(OS_WIN) && !defined(USE_AURA) | 1182 #if defined(OS_WIN) && !defined(USE_AURA) |
1173 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { | 1183 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { |
| 1184 // Attempt to unsnap if we're in metro snap mode. |
| 1185 if (mode_ == METRO_SNAP) { |
| 1186 HMODULE metro = base::win::GetMetroModule(); |
| 1187 if (metro) { |
| 1188 base::win::MetroUnsnapFn metro_unsnap_fn = |
| 1189 reinterpret_cast<base::win::MetroUnsnapFn>( |
| 1190 ::GetProcAddress(metro, "MetroUnsnap")); |
| 1191 if (metro_unsnap_fn) { |
| 1192 metro_unsnap_fn(); |
| 1193 return; |
| 1194 } |
| 1195 } |
| 1196 } |
| 1197 |
1174 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get()); | 1198 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get()); |
1175 if (omnibox_win) { | 1199 if (omnibox_win) { |
1176 UINT flags = event.native_event().wParam; | 1200 UINT flags = event.native_event().wParam; |
1177 gfx::Point screen_point(event.location()); | 1201 gfx::Point screen_point(event.location()); |
1178 ConvertPointToScreen(this, &screen_point); | 1202 ConvertPointToScreen(this, &screen_point); |
1179 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); | 1203 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); |
1180 } | 1204 } |
1181 } | 1205 } |
1182 #endif | 1206 #endif |
1183 | 1207 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 } | 1523 } |
1500 | 1524 |
1501 void LocationBarView::CleanupFadeAnimation() { | 1525 void LocationBarView::CleanupFadeAnimation() { |
1502 // Since we're no longer animating we don't need our layer. | 1526 // Since we're no longer animating we don't need our layer. |
1503 SetPaintToLayer(false); | 1527 SetPaintToLayer(false); |
1504 // Bubble labels don't need a transparent background anymore. | 1528 // Bubble labels don't need a transparent background anymore. |
1505 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1529 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
1506 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1530 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
1507 } | 1531 } |
1508 #endif // USE_AURA | 1532 #endif // USE_AURA |
OLD | NEW |