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

Side by Side Diff: chrome/browser/ui/cocoa/dev_tools_controller.mm

Issue 137483007: [DevTools] Use special resizing strategy instead of insets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed more comments Created 6 years, 10 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
« no previous file with comments | « chrome/browser/devtools/devtools_window.cc ('k') | chrome/browser/ui/gtk/browser_window_gtk.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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_.CopyFrom(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
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 ApplyDevToolsContentsResizingStrategy(
81 84 strategy_, gfx::Size(NSSizeToCGSize([self bounds].size)),
82 CGFloat width = std::max(static_cast<CGFloat>(0), 85 [self flipNSRectToRect:[devToolsView_ bounds]],
83 NSWidth(bounds) - contentsInsets_.width()); 86 [self flipNSRectToRect:[contentsView_ bounds]],
84 CGFloat height = std::max(static_cast<CGFloat>(0), 87 &new_devtools_bounds, &new_contents_bounds);
85 NSHeight(bounds) - contentsInsets_.height()); 88 [devToolsView_ setFrame:[self flipRectToNSRect:new_devtools_bounds]];
86 CGFloat left = std::min(static_cast<CGFloat>(contentsInsets_.left()), 89 [contentsView_ setFrame:[self flipRectToNSRect:new_contents_bounds]];
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 } 90 }
93 91
94 @end 92 @end
95 93
96 @interface DevToolsController (Private) 94 @interface DevToolsController (Private)
97 - (void)showDevToolsView; 95 - (void)showDevToolsView;
98 - (void)hideDevToolsView; 96 - (void)hideDevToolsView;
99 @end 97 @end
100 98
101 99
(...skipping 19 matching lines...) Expand all
121 DevToolsWindow::GetDockedInstanceForInspectedTab(contents) : NULL; 119 DevToolsWindow::GetDockedInstanceForInspectedTab(contents) : NULL;
122 120
123 bool shouldHide = devToolsWindow_ && devToolsWindow_ != newDevToolsWindow; 121 bool shouldHide = devToolsWindow_ && devToolsWindow_ != newDevToolsWindow;
124 bool shouldShow = newDevToolsWindow && devToolsWindow_ != newDevToolsWindow; 122 bool shouldShow = newDevToolsWindow && devToolsWindow_ != newDevToolsWindow;
125 123
126 if (shouldHide) 124 if (shouldHide)
127 [self hideDevToolsView]; 125 [self hideDevToolsView];
128 126
129 devToolsWindow_ = newDevToolsWindow; 127 devToolsWindow_ = newDevToolsWindow;
130 if (devToolsWindow_) { 128 if (devToolsWindow_) {
131 gfx::Insets insets = devToolsWindow_->GetContentsInsets(); 129 const DevToolsContentsResizingStrategy& strategy =
130 devToolsWindow_->GetContentsResizingStrategy();
132 devToolsWindow_->web_contents()->GetView()->SetOverlayView( 131 devToolsWindow_->web_contents()->GetView()->SetOverlayView(
133 contents->GetView(), gfx::Point(insets.left(), insets.top())); 132 contents->GetView(),
134 [devToolsContainerView_ setContentsInsets:insets]; 133 gfx::Point(strategy.insets().left(), strategy.insets().top()));
134 [devToolsContainerView_ setContentsResizingStrategy:strategy];
135 } else { 135 } else {
136 gfx::Insets zeroInsets; 136 DevToolsContentsResizingStrategy zeroStrategy;
137 [devToolsContainerView_ setContentsInsets:zeroInsets]; 137 [devToolsContainerView_ setContentsResizingStrategy:zeroStrategy];
138 } 138 }
139 139
140 if (shouldShow) 140 if (shouldShow)
141 [self showDevToolsView]; 141 [self showDevToolsView];
142 142
143 [devToolsContainerView_ adjustSubviews]; 143 [devToolsContainerView_ adjustSubviews];
144 if (shouldHide || shouldShow) 144 if (shouldHide || shouldShow)
145 [[devToolsContainerView_ window] disableScreenUpdatesUntilFlush]; 145 [[devToolsContainerView_ window] disableScreenUpdatesUntilFlush];
146 } 146 }
147 147
(...skipping 12 matching lines...) Expand all
160 } 160 }
161 161
162 - (void)hideDevToolsView { 162 - (void)hideDevToolsView {
163 devToolsWindow_->web_contents()->GetView()->RemoveOverlayView(); 163 devToolsWindow_->web_contents()->GetView()->RemoveOverlayView();
164 [devToolsContainerView_ hideDevTools]; 164 [devToolsContainerView_ hideDevTools];
165 [focusTracker_ restoreFocusInWindow:[devToolsContainerView_ window]]; 165 [focusTracker_ restoreFocusInWindow:[devToolsContainerView_ window]];
166 focusTracker_.reset(); 166 focusTracker_.reset();
167 } 167 }
168 168
169 @end 169 @end
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_window.cc ('k') | chrome/browser/ui/gtk/browser_window_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698