Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 11416042: views: Change the LocationBarView delegate's API to GetWebContents(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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()));
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
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 TabContents::FromWebContents(delegate_->GetWebContents());
tfarina 2012/11/16 21:42:19 This is segfaulting. I'm looking into this :/
1158 } 1146 }
1159 1147
1160 int LocationBarView::AvailableWidth(int location_bar_width) { 1148 int LocationBarView::AvailableWidth(int location_bar_width) {
1161 return location_bar_width - location_entry_->TextWidth(); 1149 return location_bar_width - location_entry_->TextWidth();
1162 } 1150 }
1163 1151
1164 void LocationBarView::LayoutView(views::View* view, 1152 void LocationBarView::LayoutView(views::View* view,
1165 int padding, 1153 int padding,
1166 int available_width, 1154 int available_width,
1167 bool leading, 1155 bool leading,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 // Remember the previous visibility of the page actions so that we can 1189 // Remember the previous visibility of the page actions so that we can
1202 // notify when this changes. 1190 // notify when this changes.
1203 std::map<ExtensionAction*, bool> old_visibility; 1191 std::map<ExtensionAction*, bool> old_visibility;
1204 for (PageActionViews::const_iterator i(page_action_views_.begin()); 1192 for (PageActionViews::const_iterator i(page_action_views_.begin());
1205 i != page_action_views_.end(); ++i) { 1193 i != page_action_views_.end(); ++i) {
1206 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); 1194 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible();
1207 } 1195 }
1208 1196
1209 std::vector<ExtensionAction*> new_page_actions; 1197 std::vector<ExtensionAction*> new_page_actions;
1210 1198
1211 WebContents* contents = GetWebContentsFromDelegate(delegate_); 1199 WebContents* contents = delegate_->GetWebContents();
1212 if (contents) { 1200 if (contents) {
1213 extensions::TabHelper* extensions_tab_helper = 1201 extensions::TabHelper* extensions_tab_helper =
1214 extensions::TabHelper::FromWebContents(contents); 1202 extensions::TabHelper::FromWebContents(contents);
1215 extensions::LocationBarController* controller = 1203 extensions::LocationBarController* controller =
1216 extensions_tab_helper->location_bar_controller(); 1204 extensions_tab_helper->location_bar_controller();
1217 new_page_actions = controller->GetCurrentActions(); 1205 new_page_actions = controller->GetCurrentActions();
1218 } 1206 }
1219 1207
1220 // On startup we sometimes haven't loaded any extensions. This makes sure 1208 // On startup we sometimes haven't loaded any extensions. This makes sure
1221 // we catch up when the extensions (and any page actions) load. 1209 // we catch up when the extensions (and any page actions) load.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 gfx::Point screen_point(event.location()); 1259 gfx::Point screen_point(event.location());
1272 ConvertPointToScreen(this, &screen_point); 1260 ConvertPointToScreen(this, &screen_point);
1273 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); 1261 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT());
1274 } 1262 }
1275 } 1263 }
1276 #endif 1264 #endif
1277 1265
1278 void LocationBarView::ShowFirstRunBubbleInternal() { 1266 void LocationBarView::ShowFirstRunBubbleInternal() {
1279 #if !defined(OS_CHROMEOS) 1267 #if !defined(OS_CHROMEOS)
1280 // First run bubble doesn't make sense for Chrome OS. 1268 // First run bubble doesn't make sense for Chrome OS.
1281 Browser* browser = GetBrowserFromDelegate(delegate_); 1269 Browser* browser = browser::FindBrowserWithWebContents(
1270 delegate_->GetWebContents());
1282 FirstRunBubble::ShowBubble(browser, location_icon_view_); 1271 FirstRunBubble::ShowBubble(browser, location_icon_view_);
1283 #endif 1272 #endif
1284 } 1273 }
1285 1274
1286 void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) { 1275 void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) {
1287 TabContents* tab_contents = GetTabContents(); 1276 TabContents* tab_contents = GetTabContents();
1288 // tab_contents may be NULL while the browser is shutting down. 1277 // tab_contents may be NULL while the browser is shutting down.
1289 if (tab_contents == NULL) 1278 if (tab_contents == NULL)
1290 return; 1279 return;
1291 1280
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), 1371 button_drag_utils::SetURLAndDragImage(web_contents->GetURL(),
1383 web_contents->GetTitle(), 1372 web_contents->GetTitle(),
1384 favicon, 1373 favicon,
1385 data, 1374 data,
1386 sender->GetWidget()); 1375 sender->GetWidget());
1387 } 1376 }
1388 1377
1389 int LocationBarView::GetDragOperationsForView(views::View* sender, 1378 int LocationBarView::GetDragOperationsForView(views::View* sender,
1390 const gfx::Point& p) { 1379 const gfx::Point& p) {
1391 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_)); 1380 DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_));
1392 WebContents* web_contents = GetWebContentsFromDelegate(delegate_); 1381 WebContents* web_contents = delegate_->GetWebContents();
1393 return (web_contents && web_contents->GetURL().is_valid() && 1382 return (web_contents && web_contents->GetURL().is_valid() &&
1394 !GetLocationEntry()->IsEditingOrEmpty()) ? 1383 !GetLocationEntry()->IsEditingOrEmpty()) ?
1395 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) : 1384 (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) :
1396 ui::DragDropTypes::DRAG_NONE; 1385 ui::DragDropTypes::DRAG_NONE;
1397 } 1386 }
1398 1387
1399 bool LocationBarView::CanStartDragForView(View* sender, 1388 bool LocationBarView::CanStartDragForView(View* sender,
1400 const gfx::Point& press_pt, 1389 const gfx::Point& press_pt,
1401 const gfx::Point& p) { 1390 const gfx::Point& p) {
1402 return true; 1391 return true;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 } 1596 }
1608 1597
1609 void LocationBarView::CleanupFadeAnimation() { 1598 void LocationBarView::CleanupFadeAnimation() {
1610 // Since we're no longer animating we don't need our layer. 1599 // Since we're no longer animating we don't need our layer.
1611 SetPaintToLayer(false); 1600 SetPaintToLayer(false);
1612 // Bubble labels don't need a transparent background anymore. 1601 // Bubble labels don't need a transparent background anymore.
1613 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1602 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1614 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); 1603 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE);
1615 } 1604 }
1616 #endif // USE_AURA 1605 #endif // USE_AURA
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/location_bar/zoom_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698