Commit 2251f312 authored by David Bienvenu's avatar David Bienvenu Committed by Commit Bot

Ensure that devtools stays visible when window is made smaller.

Original CL - https://chromium-review.googlesource.com/c/chromium/src/+/1665550

Original CL didn't account for left and bottom docked dev tools. This
CL handles those cases by looking at the incoming strategy.bounds.

Bug: 974178
Change-Id: Ic2b7f0b8b642d884f563815b2ccc94a94d423eeb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2472612Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: David Bienvenu <davidbienvenu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817363}
parent 0ea06548
...@@ -6,28 +6,30 @@ ...@@ -6,28 +6,30 @@
#include <algorithm> #include <algorithm>
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() #include "base/check_op.h"
: hide_inspected_contents_(false) {
} DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() = default;
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy(
const gfx::Rect& bounds) const gfx::Rect& bounds,
bool is_docked)
: bounds_(bounds), : bounds_(bounds),
hide_inspected_contents_(bounds_.IsEmpty() && !bounds_.x() && hide_inspected_contents_(bounds_.IsEmpty() && !bounds_.x() &&
!bounds_.y()) { !bounds_.y()),
} is_docked_(is_docked) {}
void DevToolsContentsResizingStrategy::CopyFrom( void DevToolsContentsResizingStrategy::CopyFrom(
const DevToolsContentsResizingStrategy& strategy) { const DevToolsContentsResizingStrategy& strategy) {
bounds_ = strategy.bounds(); bounds_ = strategy.bounds();
hide_inspected_contents_ = strategy.hide_inspected_contents(); hide_inspected_contents_ = strategy.hide_inspected_contents();
is_docked_ = strategy.is_docked();
} }
bool DevToolsContentsResizingStrategy::Equals( bool DevToolsContentsResizingStrategy::Equals(
const DevToolsContentsResizingStrategy& strategy) { const DevToolsContentsResizingStrategy& strategy) {
return bounds_ == strategy.bounds() && return bounds_ == strategy.bounds() &&
hide_inspected_contents_ == strategy.hide_inspected_contents(); hide_inspected_contents_ == strategy.hide_inspected_contents() &&
is_docked_ == strategy.is_docked();
} }
void ApplyDevToolsContentsResizingStrategy( void ApplyDevToolsContentsResizingStrategy(
...@@ -39,6 +41,7 @@ void ApplyDevToolsContentsResizingStrategy( ...@@ -39,6 +41,7 @@ void ApplyDevToolsContentsResizingStrategy(
0, 0, container_size.width(), container_size.height()); 0, 0, container_size.width(), container_size.height());
const gfx::Rect& bounds = strategy.bounds(); const gfx::Rect& bounds = strategy.bounds();
if (bounds.size().IsEmpty() && !strategy.hide_inspected_contents()) { if (bounds.size().IsEmpty() && !strategy.hide_inspected_contents()) {
new_contents_bounds->SetRect( new_contents_bounds->SetRect(
0, 0, container_size.width(), container_size.height()); 0, 0, container_size.width(), container_size.height());
...@@ -49,5 +52,22 @@ void ApplyDevToolsContentsResizingStrategy( ...@@ -49,5 +52,22 @@ void ApplyDevToolsContentsResizingStrategy(
int top = std::min(bounds.y(), container_size.height()); int top = std::min(bounds.y(), container_size.height());
int width = std::min(bounds.width(), container_size.width() - left); int width = std::min(bounds.width(), container_size.width() - left);
int height = std::min(bounds.height(), container_size.height() - top); int height = std::min(bounds.height(), container_size.height() - top);
if (strategy.is_docked()) {
// Devtools console requires at least 240 pixels when docked.
// https://cs.chromium.org/chromium/src/third_party/blink/renderer/devtools/front_end/ui/InspectorView.js?l=38&rcl=f8763532a3fe4f7d028f4cb23f56b289efbb70c0
constexpr int kDevtoolsMinWidth = 240;
// If container_size.width() == bounds.width(), dev tools is docked at
// the bottom, otherwise it's docked to the right or left.
const int available_content_width = container_size.width() == bounds.width()
? bounds.width()
: container_size.width() - width;
DCHECK_GE(available_content_width, 0);
if (available_content_width < kDevtoolsMinWidth) {
const int width_adjustment = kDevtoolsMinWidth - available_content_width;
DCHECK_GE(width, width_adjustment);
width -= width_adjustment;
}
}
new_contents_bounds->SetRect(left, top, width, height); new_contents_bounds->SetRect(left, top, width, height);
} }
...@@ -15,21 +15,24 @@ ...@@ -15,21 +15,24 @@
class DevToolsContentsResizingStrategy { class DevToolsContentsResizingStrategy {
public: public:
DevToolsContentsResizingStrategy(); DevToolsContentsResizingStrategy();
explicit DevToolsContentsResizingStrategy( DevToolsContentsResizingStrategy(const gfx::Rect& bounds, bool is_docked);
const gfx::Rect& bounds);
void CopyFrom(const DevToolsContentsResizingStrategy& strategy); void CopyFrom(const DevToolsContentsResizingStrategy& strategy);
bool Equals(const DevToolsContentsResizingStrategy& strategy); bool Equals(const DevToolsContentsResizingStrategy& strategy);
const gfx::Rect& bounds() const { return bounds_; } const gfx::Rect& bounds() const { return bounds_; }
bool hide_inspected_contents() const { return hide_inspected_contents_; } bool hide_inspected_contents() const { return hide_inspected_contents_; }
bool is_docked() const { return is_docked_; }
private: private:
// Contents bounds. When non-empty, used instead of insets. // Contents bounds. When non-empty, used instead of insets.
gfx::Rect bounds_; gfx::Rect bounds_;
// Determines whether inspected contents is visible. // Whether inspected contents is hidden.
bool hide_inspected_contents_; bool hide_inspected_contents_ = false;
// Whether devtools is docked.
bool is_docked_ = false;
DISALLOW_COPY_AND_ASSIGN(DevToolsContentsResizingStrategy); DISALLOW_COPY_AND_ASSIGN(DevToolsContentsResizingStrategy);
}; };
......
...@@ -1360,7 +1360,7 @@ void DevToolsWindow::Inspect(scoped_refptr<content::DevToolsAgentHost> host) { ...@@ -1360,7 +1360,7 @@ void DevToolsWindow::Inspect(scoped_refptr<content::DevToolsAgentHost> host) {
} }
void DevToolsWindow::SetInspectedPageBounds(const gfx::Rect& rect) { void DevToolsWindow::SetInspectedPageBounds(const gfx::Rect& rect) {
DevToolsContentsResizingStrategy strategy(rect); DevToolsContentsResizingStrategy strategy(rect, is_docked_);
if (contents_resizing_strategy_.Equals(strategy)) if (contents_resizing_strategy_.Equals(strategy))
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment