| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 8 |
| 9 #include <Cocoa/Cocoa.h> | 9 #include <Cocoa/Cocoa.h> |
| 10 | 10 |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/debugger/devtools_window.h" | 12 #include "chrome/browser/debugger/devtools_window.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 16 #import "chrome/browser/ui/cocoa/view_id_util.h" | 16 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 19 | 19 |
| 20 using content::WebContents; |
| 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 // Minimal height of devtools pane or content pane when devtools are docked | 24 // Minimal height of devtools pane or content pane when devtools are docked |
| 23 // to the browser window. | 25 // to the browser window. |
| 24 const int kMinDevToolsHeight = 50; | 26 const int kMinDevToolsHeight = 50; |
| 25 const int kMinDevToolsWidth = 150; | 27 const int kMinDevToolsWidth = 150; |
| 26 const int kMinContentsSize = 50; | 28 const int kMinContentsSize = 50; |
| 27 | 29 |
| 28 } // end namespace | 30 } // end namespace |
| 29 | 31 |
| 30 | 32 |
| 31 @interface DevToolsController (Private) | 33 @interface DevToolsController (Private) |
| 32 - (void)showDevToolsContents:(TabContents*)devToolsContents | 34 - (void)showDevToolsContents:(WebContents*)devToolsContents |
| 33 withProfile:(Profile*)profile; | 35 withProfile:(Profile*)profile; |
| 34 - (void)showDevToolsContainer:(Profile*)profile; | 36 - (void)showDevToolsContainer:(Profile*)profile; |
| 35 - (void)hideDevToolsContainer:(Profile*)profile; | 37 - (void)hideDevToolsContainer:(Profile*)profile; |
| 36 - (void)resizeDevTools:(CGFloat)size; | 38 - (void)resizeDevTools:(CGFloat)size; |
| 37 @end | 39 @end |
| 38 | 40 |
| 39 | 41 |
| 40 @implementation DevToolsController | 42 @implementation DevToolsController |
| 41 | 43 |
| 42 - (id)initWithDelegate:(id<TabContentsControllerDelegate>)delegate { | 44 - (id)initWithDelegate:(id<TabContentsControllerDelegate>)delegate { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 62 } | 64 } |
| 63 | 65 |
| 64 - (NSView*)view { | 66 - (NSView*)view { |
| 65 return splitView_.get(); | 67 return splitView_.get(); |
| 66 } | 68 } |
| 67 | 69 |
| 68 - (NSSplitView*)splitView { | 70 - (NSSplitView*)splitView { |
| 69 return splitView_.get(); | 71 return splitView_.get(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 - (void)updateDevToolsForTabContents:(TabContents*)contents | 74 - (void)updateDevToolsForWebContents:(WebContents*)contents |
| 73 withProfile:(Profile*)profile { | 75 withProfile:(Profile*)profile { |
| 74 // Get current devtools content. | 76 // Get current devtools content. |
| 75 TabContentsWrapper* devToolsTab = contents ? | 77 TabContentsWrapper* devToolsTab = contents ? |
| 76 DevToolsWindow::GetDevToolsContents(contents) : NULL; | 78 DevToolsWindow::GetDevToolsContents(contents) : NULL; |
| 77 TabContents* devToolsContents = devToolsTab ? | 79 WebContents* devToolsContents = devToolsTab ? |
| 78 devToolsTab->tab_contents() : NULL; | 80 devToolsTab->web_contents() : NULL; |
| 79 | 81 |
| 80 [self showDevToolsContents:devToolsContents withProfile:profile]; | 82 [self showDevToolsContents:devToolsContents withProfile:profile]; |
| 81 } | 83 } |
| 82 | 84 |
| 83 - (void)setDockToRight:(BOOL)dockToRight | 85 - (void)setDockToRight:(BOOL)dockToRight |
| 84 withProfile:(Profile*)profile { | 86 withProfile:(Profile*)profile { |
| 85 if (dockToRight_ == dockToRight) | 87 if (dockToRight_ == dockToRight) |
| 86 return; | 88 return; |
| 87 | 89 |
| 88 NSArray* subviews = [splitView_ subviews]; | 90 NSArray* subviews = [splitView_ subviews]; |
| 89 if ([subviews count] == 2) { | 91 if ([subviews count] == 2) { |
| 90 [self hideDevToolsContainer:profile]; | 92 [self hideDevToolsContainer:profile]; |
| 91 dockToRight_ = dockToRight; | 93 dockToRight_ = dockToRight; |
| 92 [self showDevToolsContainer:profile]; | 94 [self showDevToolsContainer:profile]; |
| 93 } else { | 95 } else { |
| 94 dockToRight_ = dockToRight; | 96 dockToRight_ = dockToRight; |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 | 99 |
| 98 - (void)ensureContentsVisible { | 100 - (void)ensureContentsVisible { |
| 99 [contentsController_ ensureContentsVisible]; | 101 [contentsController_ ensureContentsVisible]; |
| 100 } | 102 } |
| 101 | 103 |
| 102 - (void)showDevToolsContents:(TabContents*)devToolsContents | 104 - (void)showDevToolsContents:(WebContents*)devToolsContents |
| 103 withProfile:(Profile*)profile { | 105 withProfile:(Profile*)profile { |
| 104 [contentsController_ ensureContentsSizeDoesNotChange]; | 106 [contentsController_ ensureContentsSizeDoesNotChange]; |
| 105 | 107 |
| 106 NSArray* subviews = [splitView_ subviews]; | 108 NSArray* subviews = [splitView_ subviews]; |
| 107 if (devToolsContents) { | 109 if (devToolsContents) { |
| 108 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was | 110 // |devToolsView| is a TabContentsViewCocoa object, whose ViewID was |
| 109 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to | 111 // set to VIEW_ID_TAB_CONTAINER initially, so we need to change it to |
| 110 // VIEW_ID_DEV_TOOLS_DOCKED here. | 112 // VIEW_ID_DEV_TOOLS_DOCKED here. |
| 111 view_id_util::SetID(devToolsContents->GetNativeView(), | 113 view_id_util::SetID(devToolsContents->GetNativeView(), |
| 112 VIEW_ID_DEV_TOOLS_DOCKED); | 114 VIEW_ID_DEV_TOOLS_DOCKED); |
| 113 [self showDevToolsContainer:profile]; | 115 [self showDevToolsContainer:profile]; |
| 114 } else { | 116 } else { |
| 115 if ([subviews count] > 1) { | 117 if ([subviews count] > 1) { |
| 116 [self hideDevToolsContainer:profile]; | 118 [self hideDevToolsContainer:profile]; |
| 117 } | 119 } |
| 118 } | 120 } |
| 119 | 121 |
| 120 [contentsController_ changeTabContents:devToolsContents]; | 122 [contentsController_ changeTabContents: |
| 123 static_cast<TabContents*>(devToolsContents)]; |
| 121 } | 124 } |
| 122 | 125 |
| 123 - (void)showDevToolsContainer:(Profile*)profile { | 126 - (void)showDevToolsContainer:(Profile*)profile { |
| 124 NSArray* subviews = [splitView_ subviews]; | 127 NSArray* subviews = [splitView_ subviews]; |
| 125 DCHECK_GE([subviews count], 1u); | 128 DCHECK_GE([subviews count], 1u); |
| 126 | 129 |
| 127 CGFloat splitOffset = 0; | 130 CGFloat splitOffset = 0; |
| 128 | 131 |
| 129 CGFloat contentSize = | 132 CGFloat contentSize = |
| 130 dockToRight_ ? NSWidth([splitView_ frame]) | 133 dockToRight_ ? NSWidth([splitView_ frame]) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // Return NO for the devTools view to indicate that it should not be resized | 216 // Return NO for the devTools view to indicate that it should not be resized |
| 214 // automatically. It preserves the height set by the user and also keeps | 217 // automatically. It preserves the height set by the user and also keeps |
| 215 // view height the same while changing tabs when one of the tabs shows infobar | 218 // view height the same while changing tabs when one of the tabs shows infobar |
| 216 // and others are not. | 219 // and others are not. |
| 217 if ([[splitView_ subviews] indexOfObject:subview] == 1) | 220 if ([[splitView_ subviews] indexOfObject:subview] == 1) |
| 218 return NO; | 221 return NO; |
| 219 return YES; | 222 return YES; |
| 220 } | 223 } |
| 221 | 224 |
| 222 @end | 225 @end |
| OLD | NEW |