Use new devtools resizing strategy from Chrome 37.

This commit is contained in:
Cheng Zhao 2014-09-01 19:15:07 +08:00
parent f8c8c415eb
commit 4107089363
6 changed files with 35 additions and 90 deletions

View file

@ -6,80 +6,48 @@
#include <algorithm>
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() {
}
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy(
const gfx::Insets& insets, const gfx::Size& min_size)
: insets_(insets),
min_size_(min_size) {
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy()
: hide_inspected_contents_(false) {
}
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy(
const gfx::Rect& bounds)
: bounds_(bounds) {
: bounds_(bounds),
hide_inspected_contents_(bounds_.IsEmpty() && !bounds_.x() &&
!bounds_.y()) {
}
void DevToolsContentsResizingStrategy::CopyFrom(
const DevToolsContentsResizingStrategy& strategy) {
insets_ = strategy.insets();
min_size_ = strategy.min_size();
bounds_ = strategy.bounds();
hide_inspected_contents_ = strategy.hide_inspected_contents();
}
bool DevToolsContentsResizingStrategy::Equals(
const DevToolsContentsResizingStrategy& strategy) {
return insets_ == strategy.insets() && min_size_ == strategy.min_size() &&
bounds_ == strategy.bounds();
return bounds_ == strategy.bounds() &&
hide_inspected_contents_ == strategy.hide_inspected_contents();
}
void ApplyDevToolsContentsResizingStrategy(
const DevToolsContentsResizingStrategy& strategy,
const gfx::Size& container_size,
const gfx::Rect& old_devtools_bounds,
const gfx::Rect& old_contents_bounds,
gfx::Rect* new_devtools_bounds,
gfx::Rect* new_contents_bounds) {
new_devtools_bounds->SetRect(
0, 0, container_size.width(), container_size.height());
const gfx::Insets& insets = strategy.insets();
const gfx::Size& min_size = strategy.min_size();
const gfx::Rect& bounds = strategy.bounds();
if (!bounds.size().IsEmpty()) {
int left = std::min(bounds.x(), container_size.width());
int top = std::min(bounds.y(), container_size.height());
int width = std::min(bounds.width(), container_size.width() - left);
int height = std::min(bounds.height(), container_size.height() - top);
new_contents_bounds->SetRect(left, top, width, height);
if (bounds.size().IsEmpty() && !strategy.hide_inspected_contents()) {
new_contents_bounds->SetRect(
0, 0, container_size.width(), container_size.height());
return;
}
int width = std::max(0, container_size.width() - insets.width());
int left = insets.left();
if (width < min_size.width() && insets.width() > 0) {
int min_width = std::min(min_size.width(), container_size.width());
int insets_width = container_size.width() - min_width;
int insets_decrease = insets.width() - insets_width;
// Decrease both left and right insets proportionally.
left -= insets_decrease * insets.left() / insets.width();
width = min_width;
}
left = std::max(0, std::min(container_size.width(), left));
int height = std::max(0, container_size.height() - insets.height());
int top = insets.top();
if (height < min_size.height() && insets.height() > 0) {
int min_height = std::min(min_size.height(), container_size.height());
int insets_height = container_size.height() - min_height;
int insets_decrease = insets.height() - insets_height;
// Decrease both top and bottom insets proportionally.
top -= insets_decrease * insets.top() / insets.height();
height = min_height;
}
top = std::max(0, std::min(container_size.height(), top));
int left = std::min(bounds.x(), container_size.width());
int top = std::min(bounds.y(), container_size.height());
int width = std::min(bounds.width(), container_size.width() - left);
int height = std::min(bounds.height(), container_size.height() - top);
new_contents_bounds->SetRect(left, top, width, height);
}

View file

@ -15,28 +15,22 @@
class DevToolsContentsResizingStrategy {
public:
DevToolsContentsResizingStrategy();
DevToolsContentsResizingStrategy(
const gfx::Insets& insets,
const gfx::Size& min_size);
explicit DevToolsContentsResizingStrategy(const gfx::Rect& bounds);
explicit DevToolsContentsResizingStrategy(
const gfx::Rect& bounds);
void CopyFrom(const DevToolsContentsResizingStrategy& strategy);
bool Equals(const DevToolsContentsResizingStrategy& strategy);
const gfx::Insets& insets() const { return insets_; }
const gfx::Size& min_size() const { return min_size_; }
const gfx::Rect& bounds() const { return bounds_; }
bool hide_inspected_contents() const { return hide_inspected_contents_; }
private:
// Insets of contents inside DevTools.
gfx::Insets insets_;
// Minimum size of contents.
gfx::Size min_size_;
// Contents bounds. When non-empty, used instead of insets.
gfx::Rect bounds_;
// Determines whether inspected contents is visible.
bool hide_inspected_contents_;
DISALLOW_COPY_AND_ASSIGN(DevToolsContentsResizingStrategy);
};
@ -48,8 +42,6 @@ class DevToolsContentsResizingStrategy {
void ApplyDevToolsContentsResizingStrategy(
const DevToolsContentsResizingStrategy& strategy,
const gfx::Size& container_size,
const gfx::Rect& old_devtools_bounds,
const gfx::Rect& old_contents_bounds,
gfx::Rect* new_devtools_bounds,
gfx::Rect* new_contents_bounds);

View file

@ -23,33 +23,20 @@ bool GetValue(const base::ListValue& list, int pos, bool& value) {
return list.GetBoolean(pos, &value);
}
bool GetValue(const base::ListValue& list, int pos, gfx::Insets& insets) {
const base::DictionaryValue* dict;
if (!list.GetDictionary(pos, &dict))
return false;
int top = 0;
int left = 0;
int bottom = 0;
int right = 0;
if (!dict->GetInteger("top", &top) ||
!dict->GetInteger("left", &left) ||
!dict->GetInteger("bottom", &bottom) ||
!dict->GetInteger("right", &right))
return false;
insets.Set(top, left, bottom, right);
return true;
}
bool GetValue(const base::ListValue& list, int pos, gfx::Size& size) {
bool GetValue(const base::ListValue& list, int pos, gfx::Rect& rect) {
const base::DictionaryValue* dict;
if (!list.GetDictionary(pos, &dict))
return false;
int x = 0;
int y = 0;
int width = 0;
int height = 0;
if (!dict->GetInteger("width", &width) ||
if (!dict->GetInteger("x", &x) ||
!dict->GetInteger("y", &y) ||
!dict->GetInteger("width", &width) ||
!dict->GetInteger("height", &height))
return false;
size.SetSize(width, height);
rect.SetRect(x, y, width, height);
return true;
}
@ -191,8 +178,8 @@ DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher(
RegisterHandler("closeWindow",
BindToListParser(base::Bind(&Delegate::CloseWindow,
base::Unretained(delegate))));
RegisterHandler("setContentsResizingStrategy",
BindToListParser(base::Bind(&Delegate::SetContentsResizingStrategy,
RegisterHandler("setInspectedPageBounds",
BindToListParser(base::Bind(&Delegate::SetInspectedPageBounds,
base::Unretained(delegate))));
RegisterHandler("inspectElementCompleted",
BindToListParser(base::Bind(&Delegate::InspectElementCompleted,

View file

@ -10,6 +10,7 @@
#include "base/callback.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
namespace base {
@ -32,8 +33,7 @@ class DevToolsEmbedderMessageDispatcher {
virtual void ActivateWindow() = 0;
virtual void CloseWindow() = 0;
virtual void SetContentsResizingStrategy(
const gfx::Insets& insets, const gfx::Size& min_size) = 0;
virtual void SetInspectedPageBounds(const gfx::Rect& rect) = 0;
virtual void InspectElementCompleted() = 0;
virtual void MoveWindow(int x, int y) = 0;
virtual void SetIsDocked(bool docked) = 0;

View file

@ -212,9 +212,8 @@ void InspectableWebContentsImpl::CloseWindow() {
devtools_web_contents()->DispatchBeforeUnload(false);
}
void InspectableWebContentsImpl::SetContentsResizingStrategy(
const gfx::Insets& insets, const gfx::Size& min_size) {
DevToolsContentsResizingStrategy strategy(insets, min_size);
void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) {
DevToolsContentsResizingStrategy strategy(rect);
if (contents_resizing_strategy_.Equals(strategy))
return;

View file

@ -64,8 +64,7 @@ class InspectableWebContentsImpl :
virtual void ActivateWindow() OVERRIDE;
virtual void CloseWindow() OVERRIDE;
virtual void SetContentsResizingStrategy(
const gfx::Insets& insets, const gfx::Size& min_size) OVERRIDE;
virtual void SetInspectedPageBounds(const gfx::Rect& rect) OVERRIDE;
virtual void InspectElementCompleted() OVERRIDE;
virtual void MoveWindow(int x, int y) OVERRIDE;
virtual void SetIsDocked(bool docked) OVERRIDE;