| 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 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" | 5 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include <Cocoa/Cocoa.h> | 10 #include <Cocoa/Cocoa.h> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 109 } |
| 110 return self; | 110 return self; |
| 111 } | 111 } |
| 112 | 112 |
| 113 - (NSView*)view { | 113 - (NSView*)view { |
| 114 return devToolsContainerView_.get(); | 114 return devToolsContainerView_.get(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 - (void)updateDevToolsForWebContents:(WebContents*)contents | 117 - (void)updateDevToolsForWebContents:(WebContents*)contents |
| 118 withProfile:(Profile*)profile { | 118 withProfile:(Profile*)profile { |
| 119 DevToolsWindow* newDevToolsWindow = contents ? | 119 DevToolsContentsResizingStrategy strategy; |
| 120 DevToolsWindow::GetDockedInstanceForInspectedTab(contents) : NULL; | 120 WebContents* devTools = DevToolsWindow::GetInTabWebContents( |
| 121 contents, &strategy); |
| 121 | 122 |
| 122 // Make sure we do not draw any transient arrangements of views. | 123 // Make sure we do not draw any transient arrangements of views. |
| 123 gfx::ScopedNSDisableScreenUpdates disabler; | 124 gfx::ScopedNSDisableScreenUpdates disabler; |
| 124 bool shouldHide = devToolsWindow_ && devToolsWindow_ != newDevToolsWindow; | 125 bool shouldHide = devTools_ && devTools_ != devTools; |
| 125 bool shouldShow = newDevToolsWindow && devToolsWindow_ != newDevToolsWindow; | 126 bool shouldShow = devTools && devTools_ != devTools; |
| 126 | 127 |
| 127 if (shouldHide) | 128 if (shouldHide) |
| 128 [self hideDevToolsView]; | 129 [self hideDevToolsView]; |
| 129 | 130 |
| 130 devToolsWindow_ = newDevToolsWindow; | 131 devTools_ = devTools; |
| 131 if (devToolsWindow_) { | 132 if (devTools_) { |
| 132 const DevToolsContentsResizingStrategy& strategy = | 133 devTools_->SetOverlayView( |
| 133 devToolsWindow_->GetContentsResizingStrategy(); | |
| 134 devToolsWindow_->web_contents()->SetOverlayView( | |
| 135 contents, | 134 contents, |
| 136 gfx::Point(strategy.insets().left(), strategy.insets().top())); | 135 gfx::Point(strategy.insets().left(), strategy.insets().top())); |
| 137 [devToolsContainerView_ setContentsResizingStrategy:strategy]; | 136 [devToolsContainerView_ setContentsResizingStrategy:strategy]; |
| 138 } else { | 137 } else { |
| 139 DevToolsContentsResizingStrategy zeroStrategy; | 138 DevToolsContentsResizingStrategy zeroStrategy; |
| 140 [devToolsContainerView_ setContentsResizingStrategy:zeroStrategy]; | 139 [devToolsContainerView_ setContentsResizingStrategy:zeroStrategy]; |
| 141 } | 140 } |
| 142 | 141 |
| 143 if (shouldShow) | 142 if (shouldShow) |
| 144 [self showDevToolsView]; | 143 [self showDevToolsView]; |
| 145 | 144 |
| 146 [devToolsContainerView_ adjustSubviews]; | 145 [devToolsContainerView_ adjustSubviews]; |
| 147 } | 146 } |
| 148 | 147 |
| 149 - (void)showDevToolsView { | 148 - (void)showDevToolsView { |
| 150 focusTracker_.reset( | 149 focusTracker_.reset( |
| 151 [[FocusTracker alloc] initWithWindow:[devToolsContainerView_ window]]); | 150 [[FocusTracker alloc] initWithWindow:[devToolsContainerView_ window]]); |
| 152 | 151 |
| 153 // |devToolsView| is a WebContentsViewCocoa object, whose ViewID was | 152 // |devToolsView| is a WebContentsViewCocoa object, whose ViewID was |
| 154 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to | 153 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to |
| 155 // VIEW_ID_DEV_TOOLS_DOCKED here. | 154 // VIEW_ID_DEV_TOOLS_DOCKED here. |
| 156 NSView* devToolsView = devToolsWindow_->web_contents()->GetNativeView(); | 155 NSView* devToolsView = devTools_->GetNativeView(); |
| 157 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED); | 156 view_id_util::SetID(devToolsView, VIEW_ID_DEV_TOOLS_DOCKED); |
| 158 | 157 |
| 159 [devToolsContainerView_ showDevTools:devToolsView]; | 158 [devToolsContainerView_ showDevTools:devToolsView]; |
| 160 } | 159 } |
| 161 | 160 |
| 162 - (void)hideDevToolsView { | 161 - (void)hideDevToolsView { |
| 163 devToolsWindow_->web_contents()->RemoveOverlayView(); | 162 devTools_->RemoveOverlayView(); |
| 164 [devToolsContainerView_ hideDevTools]; | 163 [devToolsContainerView_ hideDevTools]; |
| 165 [focusTracker_ restoreFocusInWindow:[devToolsContainerView_ window]]; | 164 [focusTracker_ restoreFocusInWindow:[devToolsContainerView_ window]]; |
| 166 focusTracker_.reset(); | 165 focusTracker_.reset(); |
| 167 } | 166 } |
| 168 | 167 |
| 169 @end | 168 @end |
| OLD | NEW |