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

Side by Side Diff: chrome/browser/devtools/devtools_contents_resizing_strategy.cc

Issue 440663003: DevTools: remove unused resizing strategy code paths, make it solely bounds-based. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for landing Created 6 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/devtools/devtools_contents_resizing_strategy.h" 5 #include "chrome/browser/devtools/devtools_contents_resizing_strategy.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() { 9 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy()
10 } 10 : hide_inspected_contents_(false) {
11
12 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy(
13 const gfx::Insets& insets, const gfx::Size& min_size)
14 : insets_(insets),
15 min_size_(min_size) {
16 } 11 }
17 12
18 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( 13 DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy(
19 const gfx::Rect& bounds) 14 const gfx::Rect& bounds)
20 : bounds_(bounds) { 15 : bounds_(bounds),
16 hide_inspected_contents_(bounds_.IsEmpty() && !bounds_.x() &&
17 !bounds_.y()) {
21 } 18 }
22 19
23 20
24 void DevToolsContentsResizingStrategy::CopyFrom( 21 void DevToolsContentsResizingStrategy::CopyFrom(
25 const DevToolsContentsResizingStrategy& strategy) { 22 const DevToolsContentsResizingStrategy& strategy) {
26 insets_ = strategy.insets();
27 min_size_ = strategy.min_size();
28 bounds_ = strategy.bounds(); 23 bounds_ = strategy.bounds();
24 hide_inspected_contents_ = strategy.hide_inspected_contents();
29 } 25 }
30 26
31 bool DevToolsContentsResizingStrategy::Equals( 27 bool DevToolsContentsResizingStrategy::Equals(
32 const DevToolsContentsResizingStrategy& strategy) { 28 const DevToolsContentsResizingStrategy& strategy) {
33 return insets_ == strategy.insets() && min_size_ == strategy.min_size() && 29 return bounds_ == strategy.bounds() &&
34 bounds_ == strategy.bounds(); 30 hide_inspected_contents_ == strategy.hide_inspected_contents();
35 } 31 }
36 32
37 void ApplyDevToolsContentsResizingStrategy( 33 void ApplyDevToolsContentsResizingStrategy(
38 const DevToolsContentsResizingStrategy& strategy, 34 const DevToolsContentsResizingStrategy& strategy,
39 const gfx::Size& container_size, 35 const gfx::Size& container_size,
40 const gfx::Rect& old_devtools_bounds,
41 const gfx::Rect& old_contents_bounds,
42 gfx::Rect* new_devtools_bounds, 36 gfx::Rect* new_devtools_bounds,
43 gfx::Rect* new_contents_bounds) { 37 gfx::Rect* new_contents_bounds) {
44 new_devtools_bounds->SetRect( 38 new_devtools_bounds->SetRect(
45 0, 0, container_size.width(), container_size.height()); 39 0, 0, container_size.width(), container_size.height());
46 40
47 const gfx::Insets& insets = strategy.insets();
48 const gfx::Size& min_size = strategy.min_size();
49 const gfx::Rect& bounds = strategy.bounds(); 41 const gfx::Rect& bounds = strategy.bounds();
50 42 if (bounds.size().IsEmpty() && !strategy.hide_inspected_contents()) {
51 if (!bounds.size().IsEmpty()) { 43 new_contents_bounds->SetRect(
52 int left = std::min(bounds.x(), container_size.width()); 44 0, 0, container_size.width(), container_size.height());
53 int top = std::min(bounds.y(), container_size.height());
54 int width = std::min(bounds.width(), container_size.width() - left);
55 int height = std::min(bounds.height(), container_size.height() - top);
56 new_contents_bounds->SetRect(left, top, width, height);
57 return; 45 return;
58 } 46 }
59 47
60 int width = std::max(0, container_size.width() - insets.width()); 48 int left = std::min(bounds.x(), container_size.width());
61 int left = insets.left(); 49 int top = std::min(bounds.y(), container_size.height());
62 if (width < min_size.width() && insets.width() > 0) { 50 int width = std::min(bounds.width(), container_size.width() - left);
63 int min_width = std::min(min_size.width(), container_size.width()); 51 int height = std::min(bounds.height(), container_size.height() - top);
64 int insets_width = container_size.width() - min_width;
65 int insets_decrease = insets.width() - insets_width;
66 // Decrease both left and right insets proportionally.
67 left -= insets_decrease * insets.left() / insets.width();
68 width = min_width;
69 }
70 left = std::max(0, std::min(container_size.width(), left));
71
72 int height = std::max(0, container_size.height() - insets.height());
73 int top = insets.top();
74 if (height < min_size.height() && insets.height() > 0) {
75 int min_height = std::min(min_size.height(), container_size.height());
76 int insets_height = container_size.height() - min_height;
77 int insets_decrease = insets.height() - insets_height;
78 // Decrease both top and bottom insets proportionally.
79 top -= insets_decrease * insets.top() / insets.height();
80 height = min_height;
81 }
82 top = std::max(0, std::min(container_size.height(), top));
83
84 new_contents_bounds->SetRect(left, top, width, height); 52 new_contents_bounds->SetRect(left, top, width, height);
85 } 53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698