chore: Move draggable regions implementation from NativeBrowserView into InspectableWebContentsView (#35007)
* hore: Move draggable regions implementation from NativeBrowserView into InspectableWebContentsView The draggable regions implementation is related to WebView, so InspectableWebContentsView is a more appropriate place to put it there. Also, this refactoring will allow the subsequent extension of the WebContentsView API, which will eventually replace BrowserView API. * fix: Lint error * fix: Adjusted owner-window
This commit is contained in:
parent
f2c341b655
commit
23d4a252c6
18 changed files with 397 additions and 360 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "shell/browser/native_browser_view_views.h"
|
||||
#include "shell/browser/native_window_views.h"
|
||||
#include "shell/browser/ui/views/inspectable_web_contents_view_views.h"
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/base/hit_test.h"
|
||||
#include "ui/views/widget/widget.h"
|
||||
|
@ -80,11 +81,11 @@ int FramelessView::NonClientHitTest(const gfx::Point& cursor) {
|
|||
return HTCLIENT;
|
||||
|
||||
// Check attached BrowserViews for potential draggable areas.
|
||||
for (auto* view : window_->browser_views()) {
|
||||
auto* native_view = static_cast<NativeBrowserViewViews*>(view);
|
||||
auto* view_draggable_region = native_view->draggable_region();
|
||||
if (view_draggable_region &&
|
||||
view_draggable_region->contains(cursor.x(), cursor.y()))
|
||||
for (auto* view : window_->inspectable_views()) {
|
||||
auto* inspectable_view =
|
||||
static_cast<InspectableWebContentsViewViews*>(view);
|
||||
if (inspectable_view->IsContainedInDraggableRegion(window_->content_view(),
|
||||
cursor))
|
||||
return HTCAPTION;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,10 @@
|
|||
#include <memory>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "shell/browser/ui/drag_util.h"
|
||||
#include "shell/browser/ui/inspectable_web_contents.h"
|
||||
#include "shell/browser/ui/inspectable_web_contents_delegate.h"
|
||||
#include "shell/browser/ui/inspectable_web_contents_view_delegate.h"
|
||||
|
@ -79,7 +81,7 @@ InspectableWebContentsView* CreateInspectableContentsView(
|
|||
|
||||
InspectableWebContentsViewViews::InspectableWebContentsViewViews(
|
||||
InspectableWebContents* inspectable_web_contents)
|
||||
: inspectable_web_contents_(inspectable_web_contents),
|
||||
: InspectableWebContentsView(inspectable_web_contents),
|
||||
devtools_web_view_(new views::WebView(nullptr)),
|
||||
title_(u"Developer Tools") {
|
||||
if (!inspectable_web_contents_->IsGuest() &&
|
||||
|
@ -103,6 +105,19 @@ InspectableWebContentsViewViews::~InspectableWebContentsViewViews() {
|
|||
devtools_window_->GetWindowBoundsInScreen());
|
||||
}
|
||||
|
||||
bool InspectableWebContentsViewViews::IsContainedInDraggableRegion(
|
||||
views::View* root_view,
|
||||
const gfx::Point& location) {
|
||||
if (!draggable_region_.get())
|
||||
return false;
|
||||
// Draggable regions are defined relative to the web contents.
|
||||
gfx::Point point_in_contents_web_view_coords(location);
|
||||
views::View::ConvertPointToTarget(root_view, this,
|
||||
&point_in_contents_web_view_coords);
|
||||
return draggable_region_->contains(point_in_contents_web_view_coords.x(),
|
||||
point_in_contents_web_view_coords.y());
|
||||
}
|
||||
|
||||
views::View* InspectableWebContentsViewViews::GetView() {
|
||||
return this;
|
||||
}
|
||||
|
@ -212,6 +227,14 @@ void InspectableWebContentsViewViews::SetTitle(const std::u16string& title) {
|
|||
}
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewViews::UpdateDraggableRegions(
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions) {
|
||||
if (&draggable_regions_ == ®ions)
|
||||
return;
|
||||
draggable_regions_ = mojo::Clone(regions);
|
||||
draggable_region_ = DraggableRegionsToSkRegion(draggable_regions_);
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewViews::Layout() {
|
||||
if (!devtools_web_view_->GetVisible()) {
|
||||
contents_web_view_->SetBoundsRect(GetContentsBounds());
|
||||
|
|
|
@ -6,10 +6,12 @@
|
|||
#define ELECTRON_SHELL_BROWSER_UI_VIEWS_INSPECTABLE_WEB_CONTENTS_VIEW_VIEWS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "chrome/browser/devtools/devtools_contents_resizing_strategy.h"
|
||||
#include "shell/browser/ui/inspectable_web_contents_view.h"
|
||||
#include "third_party/skia/include/core/SkRegion.h"
|
||||
#include "ui/views/view.h"
|
||||
|
||||
namespace views {
|
||||
|
@ -20,8 +22,6 @@ class WidgetDelegate;
|
|||
|
||||
namespace electron {
|
||||
|
||||
class InspectableWebContents;
|
||||
|
||||
class InspectableWebContentsViewViews : public InspectableWebContentsView,
|
||||
public views::View {
|
||||
public:
|
||||
|
@ -29,6 +29,9 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView,
|
|||
InspectableWebContents* inspectable_web_contents);
|
||||
~InspectableWebContentsViewViews() override;
|
||||
|
||||
bool IsContainedInDraggableRegion(views::View* root_view,
|
||||
const gfx::Point& location);
|
||||
|
||||
// InspectableWebContentsView:
|
||||
views::View* GetView() override;
|
||||
views::View* GetWebView() override;
|
||||
|
@ -40,20 +43,15 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView,
|
|||
void SetContentsResizingStrategy(
|
||||
const DevToolsContentsResizingStrategy& strategy) override;
|
||||
void SetTitle(const std::u16string& title) override;
|
||||
void UpdateDraggableRegions(
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions) override;
|
||||
|
||||
// views::View:
|
||||
void Layout() override;
|
||||
|
||||
InspectableWebContents* inspectable_web_contents() {
|
||||
return inspectable_web_contents_;
|
||||
}
|
||||
|
||||
const std::u16string& GetTitle() const { return title_; }
|
||||
|
||||
private:
|
||||
// Owns us.
|
||||
InspectableWebContents* inspectable_web_contents_;
|
||||
|
||||
std::unique_ptr<views::Widget> devtools_window_;
|
||||
views::WebView* devtools_window_web_view_ = nullptr;
|
||||
views::View* contents_web_view_ = nullptr;
|
||||
|
@ -63,6 +61,8 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView,
|
|||
bool devtools_visible_ = false;
|
||||
views::WidgetDelegate* devtools_window_delegate_ = nullptr;
|
||||
std::u16string title_;
|
||||
|
||||
std::unique_ptr<SkRegion> draggable_region_;
|
||||
};
|
||||
|
||||
} // namespace electron
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue