| 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> |
| 11 | 11 |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #import "chrome/browser/ui/cocoa/view_id_util.h" | 15 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_contents_view.h" | 18 #include "content/public/browser/web_contents_view.h" |
| 19 #include "ui/base/cocoa/base_view.h" |
| 19 #include "ui/base/cocoa/focus_tracker.h" | 20 #include "ui/base/cocoa/focus_tracker.h" |
| 20 #include "ui/gfx/size_conversions.h" | 21 #include "ui/gfx/size_conversions.h" |
| 21 | 22 |
| 22 using content::WebContents; | 23 using content::WebContents; |
| 23 | 24 |
| 24 @interface DevToolsContainerView : NSView { | 25 @interface DevToolsContainerView : BaseView { |
| 25 gfx::Insets contentsInsets_; | 26 DevToolsContentsResizingStrategy strategy_; |
| 26 | 27 |
| 27 // Weak references. Ownership via -subviews. | 28 // Weak references. Ownership via -subviews. |
| 28 NSView* devToolsView_; | 29 NSView* devToolsView_; |
| 29 NSView* contentsView_; | 30 NSView* contentsView_; |
| 30 } | 31 } |
| 31 | 32 |
| 32 - (void)setContentsInsets:(const gfx::Insets&)insets; | 33 - (void)setContentsResizingStrategy: |
| 34 (const DevToolsContentsResizingStrategy&)strategy; |
| 33 - (void)adjustSubviews; | 35 - (void)adjustSubviews; |
| 34 - (void)showDevTools:(NSView*)devToolsView; | 36 - (void)showDevTools:(NSView*)devToolsView; |
| 35 - (void)hideDevTools; | 37 - (void)hideDevTools; |
| 36 | 38 |
| 37 @end | 39 @end |
| 38 | 40 |
| 39 | 41 |
| 40 @implementation DevToolsContainerView | 42 @implementation DevToolsContainerView |
| 41 | 43 |
| 42 - (void)setContentsInsets:(const gfx::Insets&)insets { | 44 - (void)setContentsResizingStrategy: |
| 43 contentsInsets_ = insets; | 45 (const DevToolsContentsResizingStrategy&)strategy { |
| 46 strategy_ = strategy; |
| 44 } | 47 } |
| 45 | 48 |
| 46 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { | 49 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { |
| 47 [self adjustSubviews]; | 50 [self adjustSubviews]; |
| 48 } | 51 } |
| 49 | 52 |
| 50 - (void)showDevTools:(NSView*)devToolsView { | 53 - (void)showDevTools:(NSView*)devToolsView { |
| 51 NSArray* subviews = [self subviews]; | 54 NSArray* subviews = [self subviews]; |
| 52 DCHECK_EQ(1u, [subviews count]); | 55 DCHECK_EQ(1u, [subviews count]); |
| 53 contentsView_ = [subviews objectAtIndex:0]; | 56 contentsView_ = [subviews objectAtIndex:0]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 68 return; | 71 return; |
| 69 | 72 |
| 70 if (!devToolsView_) { | 73 if (!devToolsView_) { |
| 71 DCHECK_EQ(1u, [[self subviews] count]); | 74 DCHECK_EQ(1u, [[self subviews] count]); |
| 72 NSView* contents = [[self subviews] objectAtIndex:0]; | 75 NSView* contents = [[self subviews] objectAtIndex:0]; |
| 73 [contents setFrame:[self bounds]]; | 76 [contents setFrame:[self bounds]]; |
| 74 return; | 77 return; |
| 75 } | 78 } |
| 76 | 79 |
| 77 DCHECK_EQ(2u, [[self subviews] count]); | 80 DCHECK_EQ(2u, [[self subviews] count]); |
| 78 NSRect bounds = [self bounds]; | 81 gfx::Rect new_devtools_bounds; |
| 79 | 82 gfx::Rect new_contents_bounds; |
| 80 [devToolsView_ setFrame:bounds]; | 83 strategy_.Apply(gfx::Size(NSSizeToCGSize([self bounds].size)), |
| 81 | 84 [self flipNSRectToRect:[devToolsView_ bounds]], |
| 82 CGFloat width = std::max(static_cast<CGFloat>(0), | 85 [self flipNSRectToRect:[contentsView_ bounds]], |
| 83 NSWidth(bounds) - contentsInsets_.width()); | 86 &new_devtools_bounds, &new_contents_bounds); |
| 84 CGFloat height = std::max(static_cast<CGFloat>(0), | 87 [devToolsView_ setFrame:[self flipRectToNSRect:new_devtools_bounds]]; |
| 85 NSHeight(bounds) - contentsInsets_.height()); | 88 [contentsView_ setFrame:[self flipRectToNSRect:new_contents_bounds]]; |
| 86 CGFloat left = std::min(static_cast<CGFloat>(contentsInsets_.left()), | |
| 87 NSWidth(bounds)); | |
| 88 // Flip top and bottom for NSView geometry. | |
| 89 CGFloat top = std::min(static_cast<CGFloat>(contentsInsets_.bottom()), | |
| 90 NSHeight(bounds)); | |
| 91 [contentsView_ setFrame:NSMakeRect(left, top, width, height)]; | |
| 92 } | 89 } |
| 93 | 90 |
| 94 @end | 91 @end |
| 95 | 92 |
| 96 @interface DevToolsController (Private) | 93 @interface DevToolsController (Private) |
| 97 - (void)showDevToolsView; | 94 - (void)showDevToolsView; |
| 98 - (void)hideDevToolsView; | 95 - (void)hideDevToolsView; |
| 99 @end | 96 @end |
| 100 | 97 |
| 101 | 98 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 121 DevToolsWindow::GetDockedInstanceForInspectedTab(contents) : NULL; | 118 DevToolsWindow::GetDockedInstanceForInspectedTab(contents) : NULL; |
| 122 | 119 |
| 123 bool shouldHide = devToolsWindow_ && devToolsWindow_ != newDevToolsWindow; | 120 bool shouldHide = devToolsWindow_ && devToolsWindow_ != newDevToolsWindow; |
| 124 bool shouldShow = newDevToolsWindow && devToolsWindow_ != newDevToolsWindow; | 121 bool shouldShow = newDevToolsWindow && devToolsWindow_ != newDevToolsWindow; |
| 125 | 122 |
| 126 if (shouldHide) | 123 if (shouldHide) |
| 127 [self hideDevToolsView]; | 124 [self hideDevToolsView]; |
| 128 | 125 |
| 129 devToolsWindow_ = newDevToolsWindow; | 126 devToolsWindow_ = newDevToolsWindow; |
| 130 if (devToolsWindow_) { | 127 if (devToolsWindow_) { |
| 131 gfx::Insets insets = devToolsWindow_->GetContentsInsets(); | 128 const DevToolsContentsResizingStrategy& strategy = |
| 129 devToolsWindow_->GetContentsResizingStrategy(); |
| 132 devToolsWindow_->web_contents()->GetView()->SetOverlayView( | 130 devToolsWindow_->web_contents()->GetView()->SetOverlayView( |
| 133 contents->GetView(), gfx::Point(insets.left(), insets.top())); | 131 contents->GetView(), |
| 134 [devToolsContainerView_ setContentsInsets:insets]; | 132 gfx::Point(strategy.insets.left(), strategy.insets.top())); |
| 133 [devToolsContainerView_ setContentsResizingStrategy:strategy]; |
| 135 } else { | 134 } else { |
| 136 gfx::Insets zeroInsets; | 135 DevToolsContentsResizingStrategy zeroStrategy; |
| 137 [devToolsContainerView_ setContentsInsets:zeroInsets]; | 136 [devToolsContainerView_ setContentsResizingStrategy:zeroStrategy]; |
| 138 } | 137 } |
| 139 | 138 |
| 140 if (shouldShow) | 139 if (shouldShow) |
| 141 [self showDevToolsView]; | 140 [self showDevToolsView]; |
| 142 | 141 |
| 143 [devToolsContainerView_ adjustSubviews]; | 142 [devToolsContainerView_ adjustSubviews]; |
| 144 if (shouldHide || shouldShow) | 143 if (shouldHide || shouldShow) |
| 145 [[devToolsContainerView_ window] disableScreenUpdatesUntilFlush]; | 144 [[devToolsContainerView_ window] disableScreenUpdatesUntilFlush]; |
| 146 } | 145 } |
| 147 | 146 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 160 } | 159 } |
| 161 | 160 |
| 162 - (void)hideDevToolsView { | 161 - (void)hideDevToolsView { |
| 163 devToolsWindow_->web_contents()->GetView()->RemoveOverlayView(); | 162 devToolsWindow_->web_contents()->GetView()->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 |