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

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

Issue 11272015: DevTools: “Dock to right” broken after turning a tab into a window of its own. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months 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/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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 using views::ColumnSet; 154 using views::ColumnSet;
155 using views::GridLayout; 155 using views::GridLayout;
156 156
157 namespace { 157 namespace {
158 // The height of the status bubble. 158 // The height of the status bubble.
159 const int kStatusBubbleHeight = 20; 159 const int kStatusBubbleHeight = 20;
160 // The name of a key to store on the window handle so that other code can 160 // The name of a key to store on the window handle so that other code can
161 // locate this object using just the handle. 161 // locate this object using just the handle.
162 const char* const kBrowserViewKey = "__BROWSER_VIEW__"; 162 const char* const kBrowserViewKey = "__BROWSER_VIEW__";
163 163
164 // Minimal height of devtools pane or content pane when devtools are docked
165 // to the browser window.
166 const int kMinDevToolsHeight = 50;
167 const int kMinDevToolsWidth = 150;
168 const int kMinContentsSize = 50;
169
170 // The number of milliseconds between loading animation frames. 164 // The number of milliseconds between loading animation frames.
171 const int kLoadingAnimationFrameTimeMs = 30; 165 const int kLoadingAnimationFrameTimeMs = 30;
172 // The amount of space we expect the window border to take up. 166 // The amount of space we expect the window border to take up.
173 const int kWindowBorderWidth = 5; 167 const int kWindowBorderWidth = 5;
174 168
175 // How round the 'new tab' style bookmarks bar is. 169 // How round the 'new tab' style bookmarks bar is.
176 const int kNewtabBarRoundness = 5; 170 const int kNewtabBarRoundness = 5;
177 171
178 } // namespace 172 } // namespace
179 173
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 active_bookmark_bar_(NULL), 339 active_bookmark_bar_(NULL),
346 tabstrip_(NULL), 340 tabstrip_(NULL),
347 toolbar_(NULL), 341 toolbar_(NULL),
348 window_switcher_button_(NULL), 342 window_switcher_button_(NULL),
349 infobar_container_(NULL), 343 infobar_container_(NULL),
350 contents_container_(NULL), 344 contents_container_(NULL),
351 devtools_container_(NULL), 345 devtools_container_(NULL),
352 contents_(NULL), 346 contents_(NULL),
353 contents_split_(NULL), 347 contents_split_(NULL),
354 devtools_dock_side_(DEVTOOLS_DOCK_SIDE_BOTTOM), 348 devtools_dock_side_(DEVTOOLS_DOCK_SIDE_BOTTOM),
349 devtools_window_(NULL),
355 initialized_(false), 350 initialized_(false),
356 ignore_layout_(true), 351 ignore_layout_(true),
357 #if defined(OS_WIN) && !defined(USE_AURA) 352 #if defined(OS_WIN) && !defined(USE_AURA)
358 hung_window_detector_(&hung_plugin_action_), 353 hung_window_detector_(&hung_plugin_action_),
359 ticker_(0), 354 ticker_(0),
360 #endif 355 #endif
361 force_location_bar_focus_(false), 356 force_location_bar_focus_(false),
362 ALLOW_THIS_IN_INITIALIZER_LIST(color_change_listener_(this)), 357 ALLOW_THIS_IN_INITIALIZER_LIST(color_change_listener_(this)),
363 ALLOW_THIS_IN_INITIALIZER_LIST(activate_modal_dialog_factory_(this)) { 358 ALLOW_THIS_IN_INITIALIZER_LIST(activate_modal_dialog_factory_(this)) {
364 browser_->tab_strip_model()->AddObserver(this); 359 browser_->tab_strip_model()->AddObserver(this);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 if (MaybeShowBookmarkBar(chrome::GetActiveTabContents(browser_.get()))) 675 if (MaybeShowBookmarkBar(chrome::GetActiveTabContents(browser_.get())))
681 Layout(); 676 Layout();
682 } 677 }
683 678
684 void BrowserView::UpdateDevTools() { 679 void BrowserView::UpdateDevTools() {
685 UpdateDevToolsForContents(GetActiveTabContents()); 680 UpdateDevToolsForContents(GetActiveTabContents());
686 Layout(); 681 Layout();
687 } 682 }
688 683
689 684
690 void BrowserView::SetDevToolsDockSide(DevToolsDockSide side) {
691 if (devtools_dock_side_ == side)
692 return;
693
694 if (devtools_container_->visible()) {
695 HideDevToolsContainer();
696 ShowDevToolsContainer(side);
697 } else {
698 devtools_dock_side_ = side;
699 }
700 }
701
702 void BrowserView::UpdateLoadingAnimations(bool should_animate) { 685 void BrowserView::UpdateLoadingAnimations(bool should_animate) {
703 if (should_animate) { 686 if (should_animate) {
704 if (!loading_animation_timer_.IsRunning()) { 687 if (!loading_animation_timer_.IsRunning()) {
705 // Loads are happening, and the timer isn't running, so start it. 688 // Loads are happening, and the timer isn't running, so start it.
706 last_animation_time_ = base::TimeTicks::Now(); 689 last_animation_time_ = base::TimeTicks::Now();
707 loading_animation_timer_.Start(FROM_HERE, 690 loading_animation_timer_.Start(FROM_HERE,
708 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this, 691 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this,
709 &BrowserView::LoadingAnimationCallback); 692 &BrowserView::LoadingAnimationCallback);
710 } 693 }
711 } else { 694 } else {
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 } 2024 }
2042 2025
2043 bool BrowserView::MaybeShowInfoBar(TabContents* contents) { 2026 bool BrowserView::MaybeShowInfoBar(TabContents* contents) {
2044 // TODO(beng): Remove this function once the interface between 2027 // TODO(beng): Remove this function once the interface between
2045 // InfoBarContainer, DownloadShelfView and WebContents and this 2028 // InfoBarContainer, DownloadShelfView and WebContents and this
2046 // view is sorted out. 2029 // view is sorted out.
2047 return true; 2030 return true;
2048 } 2031 }
2049 2032
2050 void BrowserView::UpdateDevToolsForContents(TabContents* tab_contents) { 2033 void BrowserView::UpdateDevToolsForContents(TabContents* tab_contents) {
2051 DevToolsWindow* devtools_window = tab_contents ? 2034 DevToolsWindow* new_devtools_window = tab_contents ?
2052 DevToolsWindow::GetDockedInstanceForInspectedTab( 2035 DevToolsWindow::GetDockedInstanceForInspectedTab(
2053 tab_contents->web_contents()) : NULL; 2036 tab_contents->web_contents()) : NULL;
2054 TabContents* devtools_tab_contents = 2037 // Fast return in case of the same window having same orientation.
2055 devtools_window ? devtools_window->tab_contents() : NULL; 2038 if (devtools_window_ == new_devtools_window) {
2056 WebContents* devtools_contents = devtools_tab_contents ? 2039 if (!new_devtools_window ||
2057 devtools_tab_contents->web_contents() : NULL; 2040 (new_devtools_window->dock_side() == devtools_dock_side_)) {
2058 2041 return;
2059 if (devtools_contents == devtools_container_->web_contents()) { 2042 }
2060 if (devtools_contents &&
2061 devtools_window->dock_side() != devtools_dock_side_)
2062 SetDevToolsDockSide(devtools_window->dock_side());
2063 return;
2064 } 2043 }
2065 2044
2066 bool should_show = devtools_contents && !devtools_container_->visible(); 2045 // Replace tab contents.
2067 bool should_hide = !devtools_contents && devtools_container_->visible(); 2046 if (devtools_window_ != new_devtools_window) {
2047 devtools_container_->SetWebContents(new_devtools_window ?
2048 new_devtools_window->tab_contents()->web_contents() : NULL);
Peter Kasting 2012/10/24 21:18:09 Nit: Indent 4
pfeldman 2012/10/25 15:17:40 Done.
2049 }
2068 2050
2069 devtools_container_->SetWebContents(devtools_contents); 2051 // Store last used position.
2070 RestackLocationBarContainer(); 2052 if (devtools_window_) {
2053 if (devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT) {
2054 devtools_window_->SetWidth(
2055 contents_split_->width() - contents_split_->divider_offset());
2056 } else {
2057 devtools_window_->SetHeight(
2058 contents_split_->height() - contents_split_->divider_offset());
2059 }
2060 }
2071 2061
2072 if (should_show) 2062 // Show / hide container if necessary. Changing dock orientation is
2073 ShowDevToolsContainer(devtools_window->dock_side()); 2063 // hide + show.
2074 else if (should_hide) 2064 bool should_hide = devtools_window_ && (!new_devtools_window ||
2065 devtools_dock_side_ != new_devtools_window->dock_side());
2066 bool should_show = new_devtools_window && (!devtools_window_ || should_hide);
2067
2068 if (should_hide)
2075 HideDevToolsContainer(); 2069 HideDevToolsContainer();
2070
2071 devtools_window_ = new_devtools_window;
2072
2073 if (should_show) {
2074 devtools_dock_side_ = new_devtools_window->dock_side();
2075 ShowDevToolsContainer();
2076 } else if (new_devtools_window) {
2077 UpdateDevToolsSplitPosition();
2078 }
2076 } 2079 }
2077 2080
2078 void BrowserView::ShowDevToolsContainer(DevToolsDockSide dock_side) { 2081 void BrowserView::ShowDevToolsContainer() {
2079 devtools_dock_side_ = dock_side;
2080 if (!devtools_focus_tracker_.get()) { 2082 if (!devtools_focus_tracker_.get()) {
2081 // Install devtools focus tracker when dev tools window is shown for the 2083 // Install devtools focus tracker when dev tools window is shown for the
2082 // first time. 2084 // first time.
2083 devtools_focus_tracker_.reset( 2085 devtools_focus_tracker_.reset(
2084 new views::ExternalFocusTracker(devtools_container_, 2086 new views::ExternalFocusTracker(devtools_container_,
2085 GetFocusManager())); 2087 GetFocusManager()));
2086 } 2088 }
2087 2089 devtools_container_->SetVisible(true);
2090 devtools_dock_side_ = devtools_window_->dock_side();
2088 bool dock_to_right = devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT; 2091 bool dock_to_right = devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT;
2089
2090 int contents_size = dock_to_right ? contents_split_->width() :
2091 contents_split_->height();
2092 int min_size = dock_to_right ? kMinDevToolsWidth : kMinDevToolsHeight;
2093
2094 // Restore split offset.
2095 int split_offset = browser_->profile()->GetPrefs()->
2096 GetInteger(dock_to_right ? prefs::kDevToolsVSplitLocation :
2097 prefs::kDevToolsHSplitLocation);
2098
2099 if (split_offset == -1)
2100 split_offset = contents_size * 1 / 3;
2101
2102 // Make sure user can see both panes.
2103 split_offset = std::max(min_size, split_offset);
2104 split_offset = std::min(contents_size - kMinContentsSize, split_offset);
2105 if (split_offset < 0)
2106 split_offset = contents_size * 1 / 3;
2107 contents_split_->set_divider_offset(contents_size - split_offset);
2108
2109 devtools_container_->SetVisible(true);
2110 contents_split_->set_orientation( 2092 contents_split_->set_orientation(
2111 dock_to_right ? views::SingleSplitView::HORIZONTAL_SPLIT 2093 dock_to_right ? views::SingleSplitView::HORIZONTAL_SPLIT
2112 : views::SingleSplitView::VERTICAL_SPLIT); 2094 : views::SingleSplitView::VERTICAL_SPLIT);
2095 UpdateDevToolsSplitPosition();
2113 contents_split_->InvalidateLayout(); 2096 contents_split_->InvalidateLayout();
2114 Layout(); 2097 Layout();
2115 } 2098 }
2116 2099
2117 void BrowserView::HideDevToolsContainer() { 2100 void BrowserView::HideDevToolsContainer() {
2118 // Store split offset when hiding devtools window only.
2119 bool dock_to_right = devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT;
2120 int contents_size = dock_to_right ? contents_split_->width() :
2121 contents_split_->height();
2122
2123 browser_->profile()->GetPrefs()->SetInteger(
2124 dock_to_right ? prefs::kDevToolsVSplitLocation :
2125 prefs::kDevToolsHSplitLocation,
2126 contents_size - contents_split_->divider_offset());
2127
2128 // Restore focus to the last focused view when hiding devtools window. 2101 // Restore focus to the last focused view when hiding devtools window.
2129 devtools_focus_tracker_->FocusLastFocusedExternalView(); 2102 devtools_focus_tracker_->FocusLastFocusedExternalView();
2130
2131 devtools_container_->SetVisible(false); 2103 devtools_container_->SetVisible(false);
2132 contents_split_->InvalidateLayout(); 2104 contents_split_->InvalidateLayout();
2133 Layout(); 2105 Layout();
2134 } 2106 }
2135 2107
2108 void BrowserView::UpdateDevToolsSplitPosition() {
2109 if (devtools_window_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT) {
Peter Kasting 2012/10/24 21:18:09 Nit: Simpler: contents_split_->set_divider_offs
pfeldman 2012/10/25 15:17:40 I did not want to return the content size, because
2110 int split_offset = contents_split_->width() -
2111 devtools_window_->GetWidth(contents_split_->width());
2112 contents_split_->set_divider_offset(split_offset);
2113 } else {
2114 int split_offset = contents_split_->height() -
2115 devtools_window_->GetHeight(contents_split_->height());
2116 contents_split_->set_divider_offset(split_offset);
2117 }
2118 }
2119
2136 void BrowserView::UpdateUIForContents(TabContents* contents) { 2120 void BrowserView::UpdateUIForContents(TabContents* contents) {
2137 bool needs_layout = MaybeShowBookmarkBar(contents); 2121 bool needs_layout = MaybeShowBookmarkBar(contents);
2138 needs_layout |= MaybeShowInfoBar(contents); 2122 needs_layout |= MaybeShowInfoBar(contents);
2139 if (needs_layout) 2123 if (needs_layout)
2140 Layout(); 2124 Layout();
2141 } 2125 }
2142 2126
2143 bool BrowserView::UpdateChildViewAndLayout(views::View* new_view, 2127 bool BrowserView::UpdateChildViewAndLayout(views::View* new_view,
2144 views::View** old_view) { 2128 views::View** old_view) {
2145 DCHECK(old_view); 2129 DCHECK(old_view);
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
2630 2614
2631 Browser* modal_browser = 2615 Browser* modal_browser =
2632 browser::FindBrowserWithWebContents(active_dialog->web_contents()); 2616 browser::FindBrowserWithWebContents(active_dialog->web_contents());
2633 if (modal_browser && (browser_ != modal_browser)) { 2617 if (modal_browser && (browser_ != modal_browser)) {
2634 modal_browser->window()->FlashFrame(true); 2618 modal_browser->window()->FlashFrame(true);
2635 modal_browser->window()->Activate(); 2619 modal_browser->window()->Activate();
2636 } 2620 }
2637 2621
2638 AppModalDialogQueue::GetInstance()->ActivateModalDialog(); 2622 AppModalDialogQueue::GetInstance()->ActivateModalDialog();
2639 } 2623 }
OLDNEW
« chrome/browser/ui/views/frame/browser_view.h ('K') | « chrome/browser/ui/views/frame/browser_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698