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

Side by Side Diff: chrome/browser/ui/views/frame/browser_view.cc

Issue 63173016: DevTools: place DevTools WebContents underneath inspected WebContents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Views fixes Created 7 years 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/frame/browser_view.h" 5 #include "chrome/browser/ui/views/frame/browser_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "chrome/browser/ui/views/accessibility/invert_bubble_view.h" 61 #include "chrome/browser/ui/views/accessibility/invert_bubble_view.h"
62 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" 62 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
63 #include "chrome/browser/ui/views/avatar_menu_button.h" 63 #include "chrome/browser/ui/views/avatar_menu_button.h"
64 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 64 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
65 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" 65 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
66 #include "chrome/browser/ui/views/browser_dialogs.h" 66 #include "chrome/browser/ui/views/browser_dialogs.h"
67 #include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h" 67 #include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h"
68 #include "chrome/browser/ui/views/download/download_shelf_view.h" 68 #include "chrome/browser/ui/views/download/download_shelf_view.h"
69 #include "chrome/browser/ui/views/frame/browser_view_layout.h" 69 #include "chrome/browser/ui/views/frame/browser_view_layout.h"
70 #include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h" 70 #include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h"
71 #include "chrome/browser/ui/views/frame/contents_container.h" 71 #include "chrome/browser/ui/views/frame/contents_layout_manager.h"
72 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 72 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
73 #include "chrome/browser/ui/views/frame/native_browser_frame_factory.h" 73 #include "chrome/browser/ui/views/frame/native_browser_frame_factory.h"
74 #include "chrome/browser/ui/views/frame/top_container_view.h" 74 #include "chrome/browser/ui/views/frame/top_container_view.h"
75 #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" 75 #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h"
76 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" 76 #include "chrome/browser/ui/views/infobars/infobar_container_view.h"
77 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 77 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
78 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 78 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
79 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 79 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
80 #include "chrome/browser/ui/views/password_generation_bubble_view.h" 80 #include "chrome/browser/ui/views/password_generation_bubble_view.h"
81 #include "chrome/browser/ui/views/profile_chooser_view.h" 81 #include "chrome/browser/ui/views/profile_chooser_view.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 last_focused_view_storage_id_( 408 last_focused_view_storage_id_(
409 views::ViewStorage::GetInstance()->CreateStorageID()), 409 views::ViewStorage::GetInstance()->CreateStorageID()),
410 frame_(NULL), 410 frame_(NULL),
411 top_container_(NULL), 411 top_container_(NULL),
412 tabstrip_(NULL), 412 tabstrip_(NULL),
413 toolbar_(NULL), 413 toolbar_(NULL),
414 window_switcher_button_(NULL), 414 window_switcher_button_(NULL),
415 find_bar_host_view_(NULL), 415 find_bar_host_view_(NULL),
416 infobar_container_(NULL), 416 infobar_container_(NULL),
417 contents_web_view_(NULL), 417 contents_web_view_(NULL),
418 devtools_container_(NULL),
419 contents_container_(NULL), 418 contents_container_(NULL),
420 contents_split_(NULL),
421 devtools_dock_side_(DEVTOOLS_DOCK_SIDE_BOTTOM),
422 devtools_window_(NULL), 419 devtools_window_(NULL),
423 initialized_(false), 420 initialized_(false),
424 in_process_fullscreen_(false), 421 in_process_fullscreen_(false),
425 #if defined(OS_WIN) && !defined(USE_AURA) 422 #if defined(OS_WIN) && !defined(USE_AURA)
426 hung_window_detector_(&hung_plugin_action_), 423 hung_window_detector_(&hung_plugin_action_),
427 ticker_(0), 424 ticker_(0),
428 #endif 425 #endif
429 force_location_bar_focus_(false), 426 force_location_bar_focus_(false),
430 immersive_mode_controller_(chrome::CreateImmersiveModeController()), 427 immersive_mode_controller_(chrome::CreateImmersiveModeController()),
431 #if defined(OS_CHROMEOS) 428 #if defined(OS_CHROMEOS)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 reinterpret_cast<BrowserView*>(widget->GetNativeWindowProperty( 500 reinterpret_cast<BrowserView*>(widget->GetNativeWindowProperty(
504 kBrowserViewKey)) : NULL; 501 kBrowserViewKey)) : NULL;
505 } 502 }
506 503
507 // static 504 // static
508 BrowserView* BrowserView::GetBrowserViewForBrowser(const Browser* browser) { 505 BrowserView* BrowserView::GetBrowserViewForBrowser(const Browser* browser) {
509 return static_cast<BrowserView*>(browser->window()); 506 return static_cast<BrowserView*>(browser->window());
510 } 507 }
511 508
512 void BrowserView::InitStatusBubble() { 509 void BrowserView::InitStatusBubble() {
513 status_bubble_.reset(new StatusBubbleViews(contents_container_)); 510 status_bubble_.reset(new StatusBubbleViews(contents_web_view_));
514 } 511 }
515 512
516 gfx::Rect BrowserView::GetToolbarBounds() const { 513 gfx::Rect BrowserView::GetToolbarBounds() const {
517 gfx::Rect toolbar_bounds(toolbar_->bounds()); 514 gfx::Rect toolbar_bounds(toolbar_->bounds());
518 if (toolbar_bounds.IsEmpty()) 515 if (toolbar_bounds.IsEmpty())
519 return toolbar_bounds; 516 return toolbar_bounds;
520 // The apparent toolbar edges are outside the "real" toolbar edges. 517 // The apparent toolbar edges are outside the "real" toolbar edges.
521 toolbar_bounds.Inset(-views::NonClientFrameView::kClientEdgeThickness, 0); 518 toolbar_bounds.Inset(-views::NonClientFrameView::kClientEdgeThickness, 0);
522 return toolbar_bounds; 519 return toolbar_bounds;
523 } 520 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 if (detached_changed && immersive_mode_controller_->IsEnabled()) 777 if (detached_changed && immersive_mode_controller_->IsEnabled())
781 change_type = BookmarkBar::DONT_ANIMATE_STATE_CHANGE; 778 change_type = BookmarkBar::DONT_ANIMATE_STATE_CHANGE;
782 779
783 bookmark_bar_view_->SetBookmarkBarState(new_state, change_type); 780 bookmark_bar_view_->SetBookmarkBarState(new_state, change_type);
784 } 781 }
785 if (MaybeShowBookmarkBar(GetActiveWebContents())) 782 if (MaybeShowBookmarkBar(GetActiveWebContents()))
786 Layout(); 783 Layout();
787 } 784 }
788 785
789 void BrowserView::UpdateDevTools() { 786 void BrowserView::UpdateDevTools() {
790 UpdateDevToolsForContents(GetActiveWebContents()); 787 UpdateDevToolsForContents(GetActiveWebContents(), true);
791 Layout(); 788 Layout();
792 } 789 }
793 790
794 void BrowserView::UpdateLoadingAnimations(bool should_animate) { 791 void BrowserView::UpdateLoadingAnimations(bool should_animate) {
795 if (should_animate) { 792 if (should_animate) {
796 if (!loading_animation_timer_.IsRunning()) { 793 if (!loading_animation_timer_.IsRunning()) {
797 // Loads are happening, and the timer isn't running, so start it. 794 // Loads are happening, and the timer isn't running, so start it.
798 last_animation_time_ = base::TimeTicks::Now(); 795 last_animation_time_ = base::TimeTicks::Now();
799 loading_animation_timer_.Start(FROM_HERE, 796 loading_animation_timer_.Start(FROM_HERE,
800 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this, 797 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this,
(...skipping 29 matching lines...) Expand all
830 // the WebContents window. 827 // the WebContents window.
831 bool change_tab_contents = 828 bool change_tab_contents =
832 contents_web_view_->web_contents() != new_contents; 829 contents_web_view_->web_contents() != new_contents;
833 830
834 // Update various elements that are interested in knowing the current 831 // Update various elements that are interested in knowing the current
835 // WebContents. 832 // WebContents.
836 833
837 // When we toggle the NTP floating bookmarks bar and/or the info bar, 834 // When we toggle the NTP floating bookmarks bar and/or the info bar,
838 // we don't want any WebContents to be attached, so that we 835 // we don't want any WebContents to be attached, so that we
839 // avoid an unnecessary resize and re-layout of a WebContents. 836 // avoid an unnecessary resize and re-layout of a WebContents.
840 if (change_tab_contents) 837 if (change_tab_contents) {
841 contents_web_view_->SetWebContents(NULL); 838 contents_web_view_->SetWebContents(NULL);
839 devtools_web_view_->SetWebContents(NULL);
840 }
842 infobar_container_->ChangeInfoBarService( 841 infobar_container_->ChangeInfoBarService(
843 InfoBarService::FromWebContents(new_contents)); 842 InfoBarService::FromWebContents(new_contents));
844 if (bookmark_bar_view_.get()) { 843 if (bookmark_bar_view_.get()) {
845 bookmark_bar_view_->SetBookmarkBarState( 844 bookmark_bar_view_->SetBookmarkBarState(
846 browser_->bookmark_bar_state(), 845 browser_->bookmark_bar_state(),
847 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); 846 BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
848 } 847 }
849 UpdateUIForContents(new_contents); 848 UpdateUIForContents(new_contents);
850 849
851 // Layout for DevTools _before_ setting the main WebContents to avoid 850 // Layout for DevTools _before_ setting the both main and devtools WebContents
852 // toggling the size of the main WebContents. 851 // to avoid toggling the size of any of them.
853 UpdateDevToolsForContents(new_contents); 852 UpdateDevToolsForContents(new_contents, !change_tab_contents);
854 853
855 if (change_tab_contents) 854 if (change_tab_contents) {
856 contents_web_view_->SetWebContents(new_contents); 855 contents_web_view_->SetWebContents(new_contents);
856 // The second layout update should be no-op. It will just set the
857 // DevTools WebContents.
858 UpdateDevToolsForContents(new_contents, true);
859 }
857 860
858 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && 861 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() &&
859 GetWidget()->IsVisible()) { 862 GetWidget()->IsVisible()) {
860 // We only restore focus if our window is visible, to avoid invoking blur 863 // We only restore focus if our window is visible, to avoid invoking blur
861 // handlers when we are eventually shown. 864 // handlers when we are eventually shown.
862 new_contents->GetView()->RestoreFocus(); 865 new_contents->GetView()->RestoreFocus();
863 } 866 }
864 867
865 // Update all the UI bits. 868 // Update all the UI bits.
866 UpdateTitleBar(); 869 UpdateTitleBar();
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 } 1017 }
1015 1018
1016 // When transitioning from animating to not animating we need to make sure the 1019 // When transitioning from animating to not animating we need to make sure the
1017 // contents_container_ gets layed out. If we don't do this and the bounds 1020 // contents_container_ gets layed out. If we don't do this and the bounds
1018 // haven't changed contents_container_ won't get a Layout out and we'll end up 1021 // haven't changed contents_container_ won't get a Layout out and we'll end up
1019 // with a gray rect because the clip wasn't updated. Note that a reentrant 1022 // with a gray rect because the clip wasn't updated. Note that a reentrant
1020 // call never needs to do this, because after it returns, the normal call 1023 // call never needs to do this, because after it returns, the normal call
1021 // wrapping it will do it. 1024 // wrapping it will do it.
1022 if ((call_state == NORMAL) && !is_animating) { 1025 if ((call_state == NORMAL) && !is_animating) {
1023 contents_web_view_->InvalidateLayout(); 1026 contents_web_view_->InvalidateLayout();
1024 contents_split_->Layout(); 1027 contents_container_->Layout();
1025 } 1028 }
1026 } 1029 }
1027 1030
1028 LocationBar* BrowserView::GetLocationBar() const { 1031 LocationBar* BrowserView::GetLocationBar() const {
1029 return GetLocationBarView(); 1032 return GetLocationBarView();
1030 } 1033 }
1031 1034
1032 void BrowserView::SetFocusToLocationBar(bool select_all) { 1035 void BrowserView::SetFocusToLocationBar(bool select_all) {
1033 // On Windows, changing focus to the location bar causes the browser 1036 // On Windows, changing focus to the location bar causes the browser
1034 // window to become active. This can steal focus if the user has 1037 // window to become active. This can steal focus if the user has
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 1284
1282 int BrowserView::GetExtraRenderViewHeight() const { 1285 int BrowserView::GetExtraRenderViewHeight() const {
1283 // Currently this is only used on linux. 1286 // Currently this is only used on linux.
1284 return 0; 1287 return 0;
1285 } 1288 }
1286 1289
1287 void BrowserView::WebContentsFocused(WebContents* contents) { 1290 void BrowserView::WebContentsFocused(WebContents* contents) {
1288 if (contents_web_view_->GetWebContents() == contents) 1291 if (contents_web_view_->GetWebContents() == contents)
1289 contents_web_view_->OnWebContentsFocused(contents); 1292 contents_web_view_->OnWebContentsFocused(contents);
1290 else 1293 else
1291 devtools_container_->OnWebContentsFocused(contents); 1294 devtools_web_view_->OnWebContentsFocused(contents);
1292 } 1295 }
1293 1296
1294 void BrowserView::ShowWebsiteSettings(Profile* profile, 1297 void BrowserView::ShowWebsiteSettings(Profile* profile,
1295 content::WebContents* web_contents, 1298 content::WebContents* web_contents,
1296 const GURL& url, 1299 const GURL& url,
1297 const content::SSLStatus& ssl) { 1300 const content::SSLStatus& ssl) {
1298 WebsiteSettingsPopupView::ShowPopup( 1301 WebsiteSettingsPopupView::ShowPopup(
1299 GetLocationBarView()->GetLocationIconView(), profile, 1302 GetLocationBarView()->GetLocationIconView(), profile,
1300 web_contents, url, ssl, browser_.get()); 1303 web_contents, url, ssl, browser_.get());
1301 } 1304 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 void BrowserView::TabDetachedAt(WebContents* contents, int index) { 1469 void BrowserView::TabDetachedAt(WebContents* contents, int index) {
1467 // We use index here rather than comparing |contents| because by this time 1470 // We use index here rather than comparing |contents| because by this time
1468 // the model has already removed |contents| from its list, so 1471 // the model has already removed |contents| from its list, so
1469 // browser_->GetActiveWebContents() will return NULL or something else. 1472 // browser_->GetActiveWebContents() will return NULL or something else.
1470 if (index == browser_->tab_strip_model()->active_index()) { 1473 if (index == browser_->tab_strip_model()->active_index()) {
1471 // We need to reset the current tab contents to NULL before it gets 1474 // We need to reset the current tab contents to NULL before it gets
1472 // freed. This is because the focus manager performs some operations 1475 // freed. This is because the focus manager performs some operations
1473 // on the selected WebContents when it is removed. 1476 // on the selected WebContents when it is removed.
1474 contents_web_view_->SetWebContents(NULL); 1477 contents_web_view_->SetWebContents(NULL);
1475 infobar_container_->ChangeInfoBarService(NULL); 1478 infobar_container_->ChangeInfoBarService(NULL);
1476 UpdateDevToolsForContents(NULL); 1479 UpdateDevToolsForContents(NULL, true);
1477 } 1480 }
1478 } 1481 }
1479 1482
1480 void BrowserView::TabDeactivated(WebContents* contents) { 1483 void BrowserView::TabDeactivated(WebContents* contents) {
1481 // We do not store the focus when closing the tab to work-around bug 4633. 1484 // We do not store the focus when closing the tab to work-around bug 4633.
1482 // Some reports seem to show that the focus manager and/or focused view can 1485 // Some reports seem to show that the focus manager and/or focused view can
1483 // be garbage at that point, it is not clear why. 1486 // be garbage at that point, it is not clear why.
1484 if (!contents->IsBeingDestroyed()) 1487 if (!contents->IsBeingDestroyed())
1485 contents->GetView()->StoreFocus(); 1488 contents->GetView()->StoreFocus();
1486 } 1489 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 // invisible or has no focusable children, it will be automatically 1746 // invisible or has no focusable children, it will be automatically
1744 // skipped. 1747 // skipped.
1745 panes->push_back(toolbar_); 1748 panes->push_back(toolbar_);
1746 if (bookmark_bar_view_.get()) 1749 if (bookmark_bar_view_.get())
1747 panes->push_back(bookmark_bar_view_.get()); 1750 panes->push_back(bookmark_bar_view_.get());
1748 if (infobar_container_) 1751 if (infobar_container_)
1749 panes->push_back(infobar_container_); 1752 panes->push_back(infobar_container_);
1750 if (download_shelf_.get()) 1753 if (download_shelf_.get())
1751 panes->push_back(download_shelf_.get()); 1754 panes->push_back(download_shelf_.get());
1752 panes->push_back(GetTabContentsContainerView()); 1755 panes->push_back(GetTabContentsContainerView());
1753 if (devtools_container_->visible()) 1756 if (devtools_web_view_->visible())
1754 panes->push_back(devtools_container_); 1757 panes->push_back(devtools_web_view_);
1755 } 1758 }
1756 1759
1757 /////////////////////////////////////////////////////////////////////////////// 1760 ///////////////////////////////////////////////////////////////////////////////
1758 // BrowserView, views::ClientView overrides: 1761 // BrowserView, views::ClientView overrides:
1759 1762
1760 bool BrowserView::CanClose() { 1763 bool BrowserView::CanClose() {
1761 // You cannot close a frame for which there is an active originating drag 1764 // You cannot close a frame for which there is an active originating drag
1762 // session. 1765 // session.
1763 if (tabstrip_ && !tabstrip_->IsTabStripCloseable()) 1766 if (tabstrip_ && !tabstrip_->IsTabStripCloseable())
1764 return false; 1767 return false;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 LoadAccelerators(); 1947 LoadAccelerators();
1945 1948
1946 infobar_container_ = new InfoBarContainerView(this); 1949 infobar_container_ = new InfoBarContainerView(this);
1947 AddChildView(infobar_container_); 1950 AddChildView(infobar_container_);
1948 1951
1949 contents_web_view_ = new views::WebView(browser_->profile()); 1952 contents_web_view_ = new views::WebView(browser_->profile());
1950 contents_web_view_->set_id(VIEW_ID_TAB_CONTAINER); 1953 contents_web_view_->set_id(VIEW_ID_TAB_CONTAINER);
1951 contents_web_view_->SetEmbedFullscreenWidgetMode( 1954 contents_web_view_->SetEmbedFullscreenWidgetMode(
1952 implicit_cast<content::WebContentsDelegate*>(browser_.get())-> 1955 implicit_cast<content::WebContentsDelegate*>(browser_.get())->
1953 EmbedsFullscreenWidget()); 1956 EmbedsFullscreenWidget());
1954 contents_container_ = new ContentsContainer(contents_web_view_);
1955 1957
1956 SkColor bg_color = GetWidget()->GetThemeProvider()-> 1958 devtools_web_view_ = new views::WebView(browser_->profile());
1957 GetColor(ThemeProperties::COLOR_TOOLBAR); 1959 devtools_web_view_->set_id(VIEW_ID_DEV_TOOLS_DOCKED);
1960 devtools_web_view_->SetVisible(false);
1958 1961
1959 devtools_container_ = new views::WebView(browser_->profile()); 1962 contents_container_ = new views::View();
1960 devtools_container_->set_id(VIEW_ID_DEV_TOOLS_DOCKED); 1963 contents_container_->AddChildView(devtools_web_view_);
1961 devtools_container_->SetVisible(false); 1964 contents_container_->AddChildView(contents_web_view_);
1962 1965 contents_container_->SetLayoutManager(new ContentsLayoutManager(
1963 views::View* contents_container_view = contents_container_; 1966 devtools_web_view_, contents_web_view_));
1964 1967 AddChildView(contents_container_);
1965 contents_split_ = new views::SingleSplitView( 1968 set_contents_view(contents_container_);
1966 contents_container_view,
1967 devtools_container_,
1968 views::SingleSplitView::VERTICAL_SPLIT,
1969 this);
1970 contents_split_->set_id(VIEW_ID_CONTENTS_SPLIT);
1971 contents_split_->SetAccessibleName(
1972 l10n_util::GetStringUTF16(IDS_ACCNAME_WEB_CONTENTS));
1973 contents_split_->set_background(
1974 views::Background::CreateSolidBackground(bg_color));
1975 AddChildView(contents_split_);
1976 set_contents_view(contents_split_);
1977 1969
1978 InitStatusBubble(); 1970 InitStatusBubble();
1979 1971
1980 // Top container holds tab strip and toolbar and lives at the front of the 1972 // Top container holds tab strip and toolbar and lives at the front of the
1981 // view hierarchy. 1973 // view hierarchy.
1982 top_container_ = new TopContainerView(this); 1974 top_container_ = new TopContainerView(this);
1983 AddChildView(top_container_); 1975 AddChildView(top_container_);
1984 1976
1985 // TabStrip takes ownership of the controller. 1977 // TabStrip takes ownership of the controller.
1986 BrowserTabStripController* tabstrip_controller = 1978 BrowserTabStripController* tabstrip_controller =
(...skipping 18 matching lines...) Expand all
2005 immersive_mode_controller_->Init(this); 1997 immersive_mode_controller_->Init(this);
2006 1998
2007 BrowserViewLayout* browser_view_layout = new BrowserViewLayout; 1999 BrowserViewLayout* browser_view_layout = new BrowserViewLayout;
2008 browser_view_layout->Init(new BrowserViewLayoutDelegateImpl(this), 2000 browser_view_layout->Init(new BrowserViewLayoutDelegateImpl(this),
2009 browser(), 2001 browser(),
2010 this, 2002 this,
2011 top_container_, 2003 top_container_,
2012 tabstrip_, 2004 tabstrip_,
2013 toolbar_, 2005 toolbar_,
2014 infobar_container_, 2006 infobar_container_,
2015 contents_split_,
2016 contents_container_, 2007 contents_container_,
2008 GetContentsLayoutManager(),
2017 immersive_mode_controller_.get()); 2009 immersive_mode_controller_.get());
2018 SetLayoutManager(browser_view_layout); 2010 SetLayoutManager(browser_view_layout);
2019 2011
2020 #if defined(OS_WIN) && !defined(USE_AURA) 2012 #if defined(OS_WIN) && !defined(USE_AURA)
2021 // Create a custom JumpList and add it to an observer of TabRestoreService 2013 // Create a custom JumpList and add it to an observer of TabRestoreService
2022 // so we can update the custom JumpList when a tab is added or removed. 2014 // so we can update the custom JumpList when a tab is added or removed.
2023 if (JumpList::Enabled()) { 2015 if (JumpList::Enabled()) {
2024 load_complete_listener_.reset(new LoadCompleteListener(this)); 2016 load_complete_listener_.reset(new LoadCompleteListener(this));
2025 } 2017 }
2026 #endif 2018 #endif
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2059 DCHECK(!jumplist_); 2051 DCHECK(!jumplist_);
2060 jumplist_ = new JumpList(); 2052 jumplist_ = new JumpList();
2061 jumplist_->AddObserver(browser_->profile()); 2053 jumplist_->AddObserver(browser_->profile());
2062 #endif 2054 #endif
2063 } 2055 }
2064 2056
2065 BrowserViewLayout* BrowserView::GetBrowserViewLayout() const { 2057 BrowserViewLayout* BrowserView::GetBrowserViewLayout() const {
2066 return static_cast<BrowserViewLayout*>(GetLayoutManager()); 2058 return static_cast<BrowserViewLayout*>(GetLayoutManager());
2067 } 2059 }
2068 2060
2061 ContentsLayoutManager* BrowserView::GetContentsLayoutManager() const {
2062 return static_cast<ContentsLayoutManager*>(
2063 contents_container_->GetLayoutManager());
2064 }
2065
2069 void BrowserView::LayoutStatusBubble() { 2066 void BrowserView::LayoutStatusBubble() {
2070 // In restored mode, the client area has a client edge between it and the 2067 // In restored mode, the client area has a client edge between it and the
2071 // frame. 2068 // frame.
2072 int overlap = StatusBubbleViews::kShadowThickness; 2069 int overlap = StatusBubbleViews::kShadowThickness;
2073 // The extra pixels defined by kClientEdgeThickness is only drawn in frame 2070 // The extra pixels defined by kClientEdgeThickness is only drawn in frame
2074 // content border on windows for non-aura build. 2071 // content border on windows for non-aura build.
2075 #if !defined(USE_ASH) 2072 #if !defined(USE_ASH)
2076 overlap += 2073 overlap +=
2077 IsMaximized() ? 0 : views::NonClientFrameView::kClientEdgeThickness; 2074 IsMaximized() ? 0 : views::NonClientFrameView::kClientEdgeThickness;
2078 #endif 2075 #endif
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2142 } 2139 }
2143 } 2140 }
2144 2141
2145 bool BrowserView::MaybeShowInfoBar(WebContents* contents) { 2142 bool BrowserView::MaybeShowInfoBar(WebContents* contents) {
2146 // TODO(beng): Remove this function once the interface between 2143 // TODO(beng): Remove this function once the interface between
2147 // InfoBarContainer, DownloadShelfView and WebContents and this 2144 // InfoBarContainer, DownloadShelfView and WebContents and this
2148 // view is sorted out. 2145 // view is sorted out.
2149 return true; 2146 return true;
2150 } 2147 }
2151 2148
2152 void BrowserView::UpdateDevToolsForContents(WebContents* web_contents) { 2149 void BrowserView::UpdateDevToolsForContents(
2150 WebContents* web_contents, bool update_devtools_web_contents) {
2153 DevToolsWindow* new_devtools_window = web_contents ? 2151 DevToolsWindow* new_devtools_window = web_contents ?
2154 DevToolsWindow::GetDockedInstanceForInspectedTab(web_contents) : NULL; 2152 DevToolsWindow::GetDockedInstanceForInspectedTab(web_contents) : NULL;
2155 // Fast return in case of the same window having same orientation. 2153
2156 if (devtools_window_ == new_devtools_window) { 2154 // Replace devtools WebContents.
2157 if (!new_devtools_window || 2155 WebContents* new_contents = new_devtools_window ?
2158 (new_devtools_window->dock_side() == devtools_dock_side_)) { 2156 new_devtools_window->web_contents() : NULL;
2159 return; 2157 if (devtools_web_view_->web_contents() != new_contents &&
2160 } 2158 update_devtools_web_contents) {
2159 devtools_web_view_->SetWebContents(new_contents);
2161 } 2160 }
2162 2161
2163 // Replace tab contents. 2162 if (!devtools_window_ && new_devtools_window &&
2164 if (devtools_window_ != new_devtools_window) { 2163 !devtools_focus_tracker_.get()) {
2165 devtools_container_->SetWebContents(
2166 new_devtools_window ? new_devtools_window->web_contents() : NULL);
2167 }
2168
2169 // Store last used position.
2170 if (devtools_window_) {
2171 int split_size = contents_split_->GetDividerSize();
2172 if (devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT) {
2173 devtools_window_->SetWidth(contents_split_->width() -
2174 split_size - contents_split_->divider_offset());
2175 } else if (devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_BOTTOM) {
2176 devtools_window_->SetHeight(contents_split_->height() -
2177 split_size - contents_split_->divider_offset());
2178 }
2179 }
2180
2181 // Show / hide container if necessary. Changing dock orientation is
2182 // hide + show.
2183 bool should_hide = devtools_window_ && (!new_devtools_window ||
2184 devtools_dock_side_ != new_devtools_window->dock_side());
2185 bool should_show = new_devtools_window && (!devtools_window_ || should_hide);
2186
2187 if (should_hide)
2188 HideDevToolsContainer();
2189
2190 devtools_window_ = new_devtools_window;
2191
2192 if (should_show) {
2193 devtools_dock_side_ = new_devtools_window->dock_side();
2194 ShowDevToolsContainer();
2195 } else if (new_devtools_window) {
2196 UpdateDevToolsSplitPosition();
2197 contents_split_->Layout();
2198 }
2199 }
2200
2201 void BrowserView::ShowDevToolsContainer() {
2202 if (!devtools_focus_tracker_.get()) {
2203 // Install devtools focus tracker when dev tools window is shown for the 2164 // Install devtools focus tracker when dev tools window is shown for the
2204 // first time. 2165 // first time.
2205 devtools_focus_tracker_.reset( 2166 devtools_focus_tracker_.reset(
2206 new views::ExternalFocusTracker(devtools_container_, 2167 new views::ExternalFocusTracker(devtools_web_view_,
2207 GetFocusManager())); 2168 GetFocusManager()));
2208 } 2169 }
2209 2170
2210 gfx::Size min_devtools_size(devtools_window_->GetMinimumWidth(), 2171 // Restore focus to the last focused view when hiding devtools window.
2211 devtools_window_->GetMinimumHeight()); 2172 if (devtools_window_ && !new_devtools_window &&
2212 devtools_container_->SetPreferredSize(min_devtools_size); 2173 devtools_focus_tracker_.get()) {
2174 devtools_focus_tracker_->FocusLastFocusedExternalView();
2175 devtools_focus_tracker_.reset();
2176 }
2213 2177
2214 devtools_container_->SetVisible(true); 2178 devtools_window_ = new_devtools_window;
2215 devtools_dock_side_ = devtools_window_->dock_side(); 2179 bool needs_layout = false;
2216 bool dock_to_right = devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT; 2180 if (devtools_window_) {
2217 contents_split_->set_orientation( 2181 devtools_web_view_->SetPreferredSize(devtools_window_->GetMinimumSize());
2218 dock_to_right ? views::SingleSplitView::HORIZONTAL_SPLIT 2182 devtools_web_view_->SetVisible(true);
2219 : views::SingleSplitView::VERTICAL_SPLIT); 2183 needs_layout = GetContentsLayoutManager()->SetContentsViewOffsets(
2220 UpdateDevToolsSplitPosition(); 2184 devtools_window_->GetTopLeftContentsOffset(),
2221 contents_split_->InvalidateLayout(); 2185 devtools_window_->GetBottomRightContentsOffset());
2222 Layout();
2223 }
2224
2225 void BrowserView::HideDevToolsContainer() {
2226 // Restore focus to the last focused view when hiding devtools window.
2227 devtools_focus_tracker_->FocusLastFocusedExternalView();
2228 devtools_container_->SetVisible(false);
2229 contents_split_->InvalidateLayout();
2230 Layout();
2231 }
2232
2233 void BrowserView::UpdateDevToolsSplitPosition() {
2234 contents_split_->set_resize_disabled(
2235 devtools_window_->dock_side() == DEVTOOLS_DOCK_SIDE_MINIMIZED);
2236 int split_size = contents_split_->GetDividerSize();
2237 if (devtools_window_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT) {
2238 int split_offset = contents_split_->width() - split_size -
2239 devtools_window_->GetWidth(contents_split_->width());
2240 contents_split_->set_divider_offset(split_offset);
2241 } else { 2186 } else {
2242 int height = devtools_window_->dock_side() == DEVTOOLS_DOCK_SIDE_MINIMIZED ? 2187 devtools_web_view_->SetVisible(false);
2243 devtools_window_->GetMinimizedHeight() : 2188 needs_layout = GetContentsLayoutManager()->SetContentsViewOffsets(
2244 devtools_window_->GetHeight(contents_split_->height()); 2189 gfx::Size(), gfx::Size());
2245 int split_offset = contents_split_->height() - split_size - height;
2246 contents_split_->set_divider_offset(split_offset);
2247 } 2190 }
2191 if (needs_layout)
2192 contents_container_->Layout();
2248 } 2193 }
2249 2194
2250 void BrowserView::UpdateUIForContents(WebContents* contents) { 2195 void BrowserView::UpdateUIForContents(WebContents* contents) {
2251 bool needs_layout = MaybeShowBookmarkBar(contents); 2196 bool needs_layout = MaybeShowBookmarkBar(contents);
2252 // TODO(jamescook): This function always returns true. Remove it and figure 2197 // TODO(jamescook): This function always returns true. Remove it and figure
2253 // out when layout is actually required. 2198 // out when layout is actually required.
2254 needs_layout |= MaybeShowInfoBar(contents); 2199 needs_layout |= MaybeShowInfoBar(contents);
2255 if (needs_layout) 2200 if (needs_layout)
2256 Layout(); 2201 Layout();
2257 } 2202 }
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
2668 !GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) { 2613 !GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) {
2669 gfx::Point icon_bottom( 2614 gfx::Point icon_bottom(
2670 toolbar_->location_bar()->GetLocationBarAnchorPoint()); 2615 toolbar_->location_bar()->GetLocationBarAnchorPoint());
2671 ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom); 2616 ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom);
2672 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); 2617 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL));
2673 ConvertPointToTarget(infobar_container_, this, &infobar_top); 2618 ConvertPointToTarget(infobar_container_, this, &infobar_top);
2674 top_arrow_height = infobar_top.y() - icon_bottom.y(); 2619 top_arrow_height = infobar_top.y() - icon_bottom.y();
2675 } 2620 }
2676 return top_arrow_height; 2621 return top_arrow_height;
2677 } 2622 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698