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 @@
#include <algorithm>
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy()
: hide_inspected_contents_(false) {
}
#include "base/check_op.h"
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() = default;
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy(
const gfx::Rect& bounds)
const gfx::Rect& bounds,
bool is_docked)
: bounds_(bounds),
hide_inspected_contents_(bounds_.IsEmpty() && !bounds_.x() &&
!bounds_.y()) {
}
!bounds_.y()),
is_docked_(is_docked) {}
void DevToolsContentsResizingStrategy::CopyFrom(
const DevToolsContentsResizingStrategy& strategy) {
bounds_ = strategy.bounds();
hide_inspected_contents_ = strategy.hide_inspected_contents();
is_docked_ = strategy.is_docked();
}
bool DevToolsContentsResizingStrategy::Equals(
const DevToolsContentsResizingStrategy& strategy) {
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(
......@@ -39,6 +41,7 @@ void ApplyDevToolsContentsResizingStrategy(
0, 0, container_size.width(), container_size.height());
const gfx::Rect& bounds = strategy.bounds();
if (bounds.size().IsEmpty() && !strategy.hide_inspected_contents()) {
new_contents_bounds->SetRect(
0, 0, container_size.width(), container_size.height());
......@@ -49,5 +52,22 @@ void ApplyDevToolsContentsResizingStrategy(
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);
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);
}
......@@ -15,21 +15,24 @@
class DevToolsContentsResizingStrategy {
public:
DevToolsContentsResizingStrategy();
explicit DevToolsContentsResizingStrategy(
const gfx::Rect& bounds);
DevToolsContentsResizingStrategy(const gfx::Rect& bounds, bool is_docked);
void CopyFrom(const DevToolsContentsResizingStrategy& strategy);
bool Equals(const DevToolsContentsResizingStrategy& strategy);
const gfx::Rect& bounds() const { return bounds_; }
bool hide_inspected_contents() const { return hide_inspected_contents_; }
bool is_docked() const { return is_docked_; }
private:
// Contents bounds. When non-empty, used instead of insets.
gfx::Rect bounds_;
// Determines whether inspected contents is visible.
bool hide_inspected_contents_;
// Whether inspected contents is hidden.
bool hide_inspected_contents_ = false;
// Whether devtools is docked.
bool is_docked_ = false;
DISALLOW_COPY_AND_ASSIGN(DevToolsContentsResizingStrategy);
};
......
......@@ -1360,7 +1360,7 @@ void DevToolsWindow::Inspect(scoped_refptr<content::DevToolsAgentHost> host) {
}
void DevToolsWindow::SetInspectedPageBounds(const gfx::Rect& rect) {
DevToolsContentsResizingStrategy strategy(rect);
DevToolsContentsResizingStrategy strategy(rect, is_docked_);
if (contents_resizing_strategy_.Equals(strategy))
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