Chromium Code Reviews| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 #if defined(USE_AURA) | 94 #if defined(USE_AURA) |
| 95 #include "ui/compositor/layer.h" | 95 #include "ui/compositor/layer.h" |
| 96 #include "ui/compositor/scoped_layer_animation_settings.h" | 96 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 97 #endif | 97 #endif |
| 98 | 98 |
| 99 using content::WebContents; | 99 using content::WebContents; |
| 100 using views::View; | 100 using views::View; |
| 101 | 101 |
| 102 namespace { | 102 namespace { |
| 103 | 103 |
| 104 WebContents* GetWebContentsFromDelegate(LocationBarView::Delegate* delegate) { | |
| 105 const TabContents* tab_contents = delegate->GetTabContents(); | |
| 106 return tab_contents ? tab_contents->web_contents() : NULL; | |
| 107 } | |
| 108 | |
| 109 Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) { | |
| 110 WebContents* contents = GetWebContentsFromDelegate(delegate); | |
| 111 return browser::FindBrowserWithWebContents(contents); | |
| 112 } | |
| 113 | |
| 114 // Height of the location bar's round corner region. | 104 // Height of the location bar's round corner region. |
| 115 const int kBorderRoundCornerHeight = 5; | 105 const int kBorderRoundCornerHeight = 5; |
| 116 // Width of location bar's round corner region. | 106 // Width of location bar's round corner region. |
| 117 const int kBorderRoundCornerWidth = 4; | 107 const int kBorderRoundCornerWidth = 4; |
| 118 // Radius of the round corners inside the location bar. | 108 // Radius of the round corners inside the location bar. |
| 119 const int kBorderCornerRadius = 2; | 109 const int kBorderCornerRadius = 2; |
| 120 | 110 |
| 121 const int kDesktopItemPadding = 3; | 111 const int kDesktopItemPadding = 3; |
| 122 const int kDesktopEdgeItemPadding = kDesktopItemPadding; | 112 const int kDesktopEdgeItemPadding = kDesktopItemPadding; |
| 123 const int kDesktopScriptBadgeItemPadding = 9; | 113 const int kDesktopScriptBadgeItemPadding = 9; |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 // Windows. | 521 // Windows. |
| 532 location_entry_->SetFocus(); | 522 location_entry_->SetFocus(); |
| 533 } | 523 } |
| 534 | 524 |
| 535 void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action, | 525 void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action, |
| 536 bool preview_enabled) { | 526 bool preview_enabled) { |
| 537 if (mode_ != NORMAL) | 527 if (mode_ != NORMAL) |
| 538 return; | 528 return; |
| 539 | 529 |
| 540 DCHECK(page_action); | 530 DCHECK(page_action); |
| 541 WebContents* contents = GetWebContentsFromDelegate(delegate_); | 531 WebContents* contents = delegate_->GetWebContents(); |
| 542 | 532 |
| 543 RefreshPageActionViews(); | 533 RefreshPageActionViews(); |
| 544 PageActionWithBadgeView* page_action_view = | 534 PageActionWithBadgeView* page_action_view = |
| 545 static_cast<PageActionWithBadgeView*>(GetPageActionView(page_action)); | 535 static_cast<PageActionWithBadgeView*>(GetPageActionView(page_action)); |
| 546 DCHECK(page_action_view); | 536 DCHECK(page_action_view); |
| 547 if (!page_action_view) | 537 if (!page_action_view) |
| 548 return; | 538 return; |
| 549 | 539 |
| 550 page_action_view->image_view()->set_preview_enabled(preview_enabled); | 540 page_action_view->image_view()->set_preview_enabled(preview_enabled); |
| 551 page_action_view->UpdateVisibility(contents, model_->GetURL()); | 541 page_action_view->UpdateVisibility(contents, model_->GetURL()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 } | 574 } |
| 585 } | 575 } |
| 586 | 576 |
| 587 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { | 577 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { |
| 588 DCHECK(zoom_view_); | 578 DCHECK(zoom_view_); |
| 589 RefreshZoomView(); | 579 RefreshZoomView(); |
| 590 | 580 |
| 591 Layout(); | 581 Layout(); |
| 592 SchedulePaint(); | 582 SchedulePaint(); |
| 593 | 583 |
| 594 if (can_show_bubble && zoom_view_->visible()) { | 584 if (can_show_bubble && zoom_view_->visible()) |
| 595 ZoomBubbleView::ShowBubble( | 585 ZoomBubbleView::ShowBubble(zoom_view_, delegate_->GetWebContents(), true); |
| 596 zoom_view_, GetWebContentsFromDelegate(delegate_), true); | |
| 597 } | |
| 598 } | 586 } |
| 599 | 587 |
| 600 void LocationBarView::RefreshZoomView() { | 588 void LocationBarView::RefreshZoomView() { |
| 601 DCHECK(zoom_view_); | 589 DCHECK(zoom_view_); |
| 602 TabContents* tab_contents = GetTabContents(); | 590 TabContents* tab_contents = GetTabContents(); |
| 603 if (!tab_contents) | 591 if (!tab_contents) |
| 604 return; | 592 return; |
| 605 | 593 |
| 606 ZoomController* zoom_controller = | 594 ZoomController* zoom_controller = |
| 607 ZoomController::FromWebContents(tab_contents->web_contents()); | 595 ZoomController::FromWebContents(tab_contents->web_contents()); |
| 608 zoom_view_->Update(zoom_controller); | 596 zoom_view_->Update(zoom_controller); |
| 609 } | 597 } |
| 610 | 598 |
| 611 void LocationBarView::ShowChromeToMobileBubble() { | 599 void LocationBarView::ShowChromeToMobileBubble() { |
| 612 chrome::ShowChromeToMobileBubbleView(action_box_button_view_, | 600 chrome::ShowChromeToMobileBubbleView(action_box_button_view_, |
| 613 GetBrowserFromDelegate(delegate_)); | 601 browser::FindBrowserWithWebContents(delegate_->GetWebContents())); |
|
Peter Kasting
2012/11/16 23:12:14
Nit: Move "action_box_button_view_," to a new 4-sp
| |
| 614 } | 602 } |
| 615 | 603 |
| 616 gfx::Point LocationBarView::GetLocationEntryOrigin() const { | 604 gfx::Point LocationBarView::GetLocationEntryOrigin() const { |
| 617 gfx::Point origin(location_entry_view_->bounds().origin()); | 605 gfx::Point origin(location_entry_view_->bounds().origin()); |
| 618 // If the UI layout is RTL, the coordinate system is not transformed and | 606 // If the UI layout is RTL, the coordinate system is not transformed and |
| 619 // therefore we need to adjust the X coordinate so that bubble appears on the | 607 // therefore we need to adjust the X coordinate so that bubble appears on the |
| 620 // right hand side of the location bar. | 608 // right hand side of the location bar. |
| 621 if (base::i18n::IsRTL()) | 609 if (base::i18n::IsRTL()) |
| 622 origin.set_x(width() - origin.x()); | 610 origin.set_x(width() - origin.x()); |
| 623 views::View::ConvertPointToScreen(this, &origin); | 611 views::View::ConvertPointToScreen(this, &origin); |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1135 views::FocusManager* focus_manager = GetFocusManager(); | 1123 views::FocusManager* focus_manager = GetFocusManager(); |
| 1136 if (!focus_manager) { | 1124 if (!focus_manager) { |
| 1137 NOTREACHED(); | 1125 NOTREACHED(); |
| 1138 return; | 1126 return; |
| 1139 } | 1127 } |
| 1140 focus_manager->SetFocusedView(this); | 1128 focus_manager->SetFocusedView(this); |
| 1141 } | 1129 } |
| 1142 | 1130 |
| 1143 gfx::Image LocationBarView::GetFavicon() const { | 1131 gfx::Image LocationBarView::GetFavicon() const { |
| 1144 return FaviconTabHelper::FromWebContents( | 1132 return FaviconTabHelper::FromWebContents( |
| 1145 delegate_->GetTabContents()->web_contents())->GetFavicon(); | 1133 delegate_->GetWebContents())->GetFavicon(); |
| 1146 } | 1134 } |
| 1147 | 1135 |
| 1148 string16 LocationBarView::GetTitle() const { | 1136 string16 LocationBarView::GetTitle() const { |
| 1149 return GetWebContentsFromDelegate(delegate_)->GetTitle(); | 1137 return delegate_->GetWebContents()->GetTitle(); |
| 1150 } | 1138 } |
| 1151 | 1139 |
| 1152 InstantController* LocationBarView::GetInstant() { | 1140 InstantController* LocationBarView::GetInstant() { |
| 1153 return delegate_->GetInstant(); | 1141 return delegate_->GetInstant(); |
| 1154 } | 1142 } |
| 1155 | 1143 |
| 1156 TabContents* LocationBarView::GetTabContents() const { | 1144 TabContents* LocationBarView::GetTabContents() const { |
| 1157 return delegate_->GetTabContents(); | 1145 return delegate_->GetWebContents() ? |
| 1146 TabContents::FromWebContents(delegate_->GetWebContents()) : NULL; | |
| 1158 } | 1147 } |
| 1159 | 1148 |
| 1160 int LocationBarView::AvailableWidth(int location_bar_width) { | 1149 int LocationBarView::AvailableWidth(int location_bar_width) { |
| 1161 return location_bar_width - location_entry_->TextWidth(); | 1150 return location_bar_width - location_entry_->TextWidth(); |
| 1162 } | 1151 } |
| 1163 | 1152 |
| 1164 void LocationBarView::LayoutView(views::View* view, | 1153 void LocationBarView::LayoutView(views::View* view, |
| 1165 int padding, | 1154 int padding, |
| 1166 int available_width, | 1155 int available_width, |
| 1167 bool leading, | 1156 bool leading, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1201 // Remember the previous visibility of the page actions so that we can | 1190 // Remember the previous visibility of the page actions so that we can |
| 1202 // notify when this changes. | 1191 // notify when this changes. |
| 1203 std::map<ExtensionAction*, bool> old_visibility; | 1192 std::map<ExtensionAction*, bool> old_visibility; |
| 1204 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 1193 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 1205 i != page_action_views_.end(); ++i) { | 1194 i != page_action_views_.end(); ++i) { |
| 1206 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); | 1195 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); |
| 1207 } | 1196 } |
| 1208 | 1197 |
| 1209 std::vector<ExtensionAction*> new_page_actions; | 1198 std::vector<ExtensionAction*> new_page_actions; |
| 1210 | 1199 |
| 1211 WebContents* contents = GetWebContentsFromDelegate(delegate_); | 1200 WebContents* contents = delegate_->GetWebContents(); |
| 1212 if (contents) { | 1201 if (contents) { |
| 1213 extensions::TabHelper* extensions_tab_helper = | 1202 extensions::TabHelper* extensions_tab_helper = |
| 1214 extensions::TabHelper::FromWebContents(contents); | 1203 extensions::TabHelper::FromWebContents(contents); |
| 1215 extensions::LocationBarController* controller = | 1204 extensions::LocationBarController* controller = |
| 1216 extensions_tab_helper->location_bar_controller(); | 1205 extensions_tab_helper->location_bar_controller(); |
| 1217 new_page_actions = controller->GetCurrentActions(); | 1206 new_page_actions = controller->GetCurrentActions(); |
| 1218 } | 1207 } |
| 1219 | 1208 |
| 1220 // On startup we sometimes haven't loaded any extensions. This makes sure | 1209 // On startup we sometimes haven't loaded any extensions. This makes sure |
| 1221 // we catch up when the extensions (and any page actions) load. | 1210 // we catch up when the extensions (and any page actions) load. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1271 gfx::Point screen_point(event.location()); | 1260 gfx::Point screen_point(event.location()); |
| 1272 ConvertPointToScreen(this, &screen_point); | 1261 ConvertPointToScreen(this, &screen_point); |
| 1273 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); | 1262 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); |
| 1274 } | 1263 } |
| 1275 } | 1264 } |
| 1276 #endif | 1265 #endif |
| 1277 | 1266 |
| 1278 void LocationBarView::ShowFirstRunBubbleInternal() { | 1267 void LocationBarView::ShowFirstRunBubbleInternal() { |
| 1279 #if !defined(OS_CHROMEOS) | 1268 #if !defined(OS_CHROMEOS) |
| 1280 // First run bubble doesn't make sense for Chrome OS. | 1269 // First run bubble doesn't make sense for Chrome OS. |
| 1281 Browser* browser = GetBrowserFromDelegate(delegate_); | 1270 Browser* browser = browser::FindBrowserWithWebContents( |
|
Peter Kasting
2012/11/16 23:12:14
Tiny nit: Prefer to linebreak after '='
| |
| 1271 delegate_->GetWebContents()); | |
| 1282 FirstRunBubble::ShowBubble(browser, location_icon_view_); | 1272 FirstRunBubble::ShowBubble(browser, location_icon_view_); |
| 1283 #endif | 1273 #endif |
| 1284 } | 1274 } |
| 1285 | 1275 |
| 1286 void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) { | 1276 void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) { |
| 1287 TabContents* tab_contents = GetTabContents(); | 1277 TabContents* tab_contents = GetTabContents(); |
| 1288 // tab_contents may be NULL while the browser is shutting down. | 1278 // tab_contents may be NULL while the browser is shutting down. |
| 1289 if (tab_contents == NULL) | 1279 if (tab_contents == NULL) |
| 1290 return; | 1280 return; |
| 1291 | 1281 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1382 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), | 1372 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), |
| 1383 web_contents->GetTitle(), | 1373 web_contents->GetTitle(), |
| 1384 favicon, | 1374 favicon, |
| 1385 data, | 1375 data, |
| 1386 sender->GetWidget()); | 1376 sender->GetWidget()); |
| 1387 } | 1377 } |
| 1388 | 1378 |
| 1389 int LocationBarView::GetDragOperationsForView(views::View* sender, | 1379 int LocationBarView::GetDragOperationsForView(views::View* sender, |
| 1390 const gfx::Point& p) { | 1380 const gfx::Point& p) { |
| 1391 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_)); | 1381 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_)); |
| 1392 WebContents* web_contents = GetWebContentsFromDelegate(delegate_); | 1382 WebContents* web_contents = delegate_->GetWebContents(); |
| 1393 return (web_contents && web_contents->GetURL().is_valid() && | 1383 return (web_contents && web_contents->GetURL().is_valid() && |
| 1394 !GetLocationEntry()->IsEditingOrEmpty()) ? | 1384 !GetLocationEntry()->IsEditingOrEmpty()) ? |
| 1395 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) : | 1385 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) : |
| 1396 ui::DragDropTypes::DRAG_NONE; | 1386 ui::DragDropTypes::DRAG_NONE; |
| 1397 } | 1387 } |
| 1398 | 1388 |
| 1399 bool LocationBarView::CanStartDragForView(View* sender, | 1389 bool LocationBarView::CanStartDragForView(View* sender, |
| 1400 const gfx::Point& press_pt, | 1390 const gfx::Point& press_pt, |
| 1401 const gfx::Point& p) { | 1391 const gfx::Point& p) { |
| 1402 return true; | 1392 return true; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1607 } | 1597 } |
| 1608 | 1598 |
| 1609 void LocationBarView::CleanupFadeAnimation() { | 1599 void LocationBarView::CleanupFadeAnimation() { |
| 1610 // Since we're no longer animating we don't need our layer. | 1600 // Since we're no longer animating we don't need our layer. |
| 1611 SetPaintToLayer(false); | 1601 SetPaintToLayer(false); |
| 1612 // Bubble labels don't need a transparent background anymore. | 1602 // Bubble labels don't need a transparent background anymore. |
| 1613 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1603 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
| 1614 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1604 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
| 1615 } | 1605 } |
| 1616 #endif // USE_AURA | 1606 #endif // USE_AURA |
| OLD | NEW |