Skip to content

Commit fcdfeb3

Browse files
OlekWhiteGreenmartin-world1977
authored andcommitted
[views] Add support for click through
1 parent 965dc4f commit fcdfeb3

11 files changed

+223
-4
lines changed

shell/browser/ui/inspectable_web_contents_view.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class InspectableWebContentsView {
4949
// GetInitiallyFocusedView() to set initial focus to web view.
5050
virtual views::View* GetWebView() = 0;
5151
virtual void SetCornerRadii(const gfx::RoundedCornersF& corner_radii) = 0;
52+
virtual void SetClickThrough(bool click_through) = 0;
5253
#else
5354
virtual gfx::NativeView GetNativeView() const = 0;
5455
#endif

shell/browser/ui/native_view.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ void NativeView::SetVisible(bool visible) {
3535
SetVisibleImpl(visible);
3636
}
3737

38+
NativeView::RoundedCornersOptions NativeView::GetRoundedCorners() const {
39+
return rounded_corners_;
40+
}
41+
3842
void NativeView::SetParent(NativeView* parent) {
3943
if (parent) {
4044
SetWindow(parent->window_);
@@ -68,9 +72,11 @@ int NativeView::GetZIndex() const {
6872
return z_index_;
6973
}
7074

75+
#if BUILDFLAG(IS_MAC)
7176
void NativeView::SetClickThrough(bool click_through) {
7277
is_click_through_ = click_through;
7378
}
79+
#endif // BUILDFLAG(IS_MAC)
7480

7581
bool NativeView::IsClickThrough() const {
7682
return is_click_through_;

shell/browser/ui/native_view.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class NativeView : public base::RefCounted<NativeView>,
221221
#endif
222222

223223
virtual void SetRoundedCorners(const RoundedCornersOptions& options);
224+
RoundedCornersOptions GetRoundedCorners() const;
224225

225226
void SetClippingInsets(const ClippingInsetOptions& options);
226227

@@ -255,7 +256,7 @@ class NativeView : public base::RefCounted<NativeView>,
255256
void SetZIndex(int z_index);
256257
int GetZIndex() const;
257258

258-
void SetClickThrough(bool click_through);
259+
virtual void SetClickThrough(bool click_through);
259260
bool IsClickThrough() const;
260261

261262
virtual void DetachChildView(NativeView* view);
@@ -322,6 +323,9 @@ class NativeView : public base::RefCounted<NativeView>,
322323
void OnViewBoundsChanged(views::View* observed_view) override;
323324
void OnViewRemovedFromWidget(views::View* observed_view) override;
324325
void OnViewIsDeleting(views::View* observed_view) override;
326+
void OnViewHierarchyChanged(
327+
views::View* observed_view,
328+
const views::ViewHierarchyChangedDetails& details) override;
325329
#endif
326330

327331
virtual void SetWindowForChildren(NativeWindow* window);
@@ -344,6 +348,7 @@ class NativeView : public base::RefCounted<NativeView>,
344348
int z_index_ = 1;
345349

346350
bool is_click_through_ = false;
351+
RoundedCornersOptions rounded_corners_;
347352

348353
#if defined(TOOLKIT_VIEWS) && !BUILDFLAG(IS_MAC)
349354
bool delete_view_ = true;

shell/browser/ui/native_view_mac.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ EventType EventTypeFromNS(NSEvent* event) {
318318
void NativeView::SetRoundedCorners(
319319
const NativeView::RoundedCornersOptions& options) {
320320
if (@available(macOS 10.13, *)) {
321+
rounded_corners_ = options;
321322
SetWantsLayer(true);
322323
auto* view = GetNative();
323324
view.layer.masksToBounds = YES;

shell/browser/ui/native_view_views.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ void NativeView::SetNativeView(NATIVEVIEW view) {
1414
if (delete_view_)
1515
delete view_;
1616
}
17+
1718
view_ = view;
1819
view_->AddObserver(this);
1920
}
@@ -53,6 +54,13 @@ void NativeView::OnViewIsDeleting(views::View* observed_view) {
5354
NotifyViewIsDeleting();
5455
}
5556

57+
void NativeView::OnViewHierarchyChanged(
58+
views::View* observed_view,
59+
const views::ViewHierarchyChangedDetails& details) {
60+
SetRoundedCorners(GetRoundedCorners());
61+
SetClickThrough(IsClickThrough());
62+
}
63+
5664
void NativeView::SetBounds(const gfx::Rect& bounds,
5765
const BoundsAnimationOptions& options) {
5866
if (view_)
@@ -124,7 +132,11 @@ void NativeView::SetBackgroundColor(SkColor color) {
124132

125133
void NativeView::SetRoundedCorners(
126134
const NativeView::RoundedCornersOptions& options) {
135+
rounded_corners_ = options;
127136
auto* view = GetNative();
137+
if (!view)
138+
return;
139+
128140
view->SetPaintToLayer();
129141
view->layer()->SetFillsBoundsOpaquely(false);
130142

@@ -137,9 +149,21 @@ void NativeView::SetRoundedCorners(
137149
view->layer()->SetIsFastRoundedCorner(true);
138150
}
139151

152+
void NativeView::SetClickThrough(bool click_through) {
153+
is_click_through_ = click_through;
154+
auto* view = GetNative();
155+
if (!view)
156+
return;
157+
158+
view->SetCanProcessEventsWithinSubtree(!click_through);
159+
}
160+
140161
void NativeView::SetClippingInsets(
141162
const NativeView::ClippingInsetOptions& options) {
142163
auto* view = GetNative();
164+
if (!view)
165+
return;
166+
143167
view->SetPaintToLayer();
144168
view->layer()->SetFillsBoundsOpaquely(false);
145169

shell/browser/ui/native_wrapper_browser_view.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class NativeWrapperBrowserView : public NativeView {
2828

2929
#if defined(TOOLKIT_VIEWS) && !BUILDFLAG(IS_MAC)
3030
void SetRoundedCorners(const RoundedCornersOptions& options) override;
31+
void SetClickThrough(bool click_through) override;
3132
#endif
3233

3334
protected:

shell/browser/ui/native_wrapper_browser_view_views.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ void NativeWrapperBrowserView::SetRoundedCorners(
3030
iwc_view->SetCornerRadii(corner_radii);
3131
}
3232

33+
void NativeWrapperBrowserView::SetClickThrough(bool click_through) {
34+
NativeView::SetClickThrough(click_through);
35+
36+
if (!api_browser_view_)
37+
return;
38+
39+
InspectableWebContentsView* iwc_view =
40+
api_browser_view_->view()->GetInspectableWebContentsView();
41+
if (!iwc_view)
42+
return;
43+
44+
iwc_view->SetClickThrough(click_through);
45+
}
46+
3347
void NativeWrapperBrowserView::InitWrapperBrowserView() {
3448
SetNativeView(new views::View());
3549
}

shell/browser/ui/views/inspectable_web_contents_view_views.cc

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "ui/views/window/client_view.h"
2222

2323
/***** stack *****/
24+
#include "ui/aura/window.h"
2425
#include "ui/base/ui_base_features.h"
2526

2627
#include "electron/shell/browser/ui/views/scroll_with_layers/native_view_host_scroll_with_layers.h"
@@ -153,13 +154,36 @@ void InspectableWebContentsViewViews::SetCornerRadii(
153154
!inspectable_web_contents_->GetWebContents()->GetNativeView()))
154155
return;
155156

157+
if (devtools_web_view_ && devtools_web_view_->GetVisible())
158+
return;
159+
156160
auto* holder = static_cast<views::WebView*>(contents_web_view_)->holder();
157161
if (!holder || !holder->GetNativeViewContainer())
158162
return;
159163

160-
if (!devtools_web_view_ || !devtools_web_view_->GetVisible()) {
161-
holder->SetCornerRadii(corner_radii);
162-
}
164+
holder->SetCornerRadii(corner_radii);
165+
}
166+
167+
void InspectableWebContentsViewViews::SetClickThrough(bool click_through) {
168+
if (!contents_web_view_ || !inspectable_web_contents_ ||
169+
(inspectable_web_contents_->IsGuest() ||
170+
!inspectable_web_contents_->GetWebContents()->GetNativeView()))
171+
return;
172+
173+
if (devtools_web_view_ && devtools_web_view_->GetVisible())
174+
return;
175+
176+
auto* holder = static_cast<views::WebView*>(contents_web_view_)->holder();
177+
if (!holder || !holder->GetNativeViewContainer())
178+
return;
179+
180+
aura::Window* native_view_container = holder->GetNativeViewContainer();
181+
if (!native_view_container)
182+
return;
183+
184+
native_view_container->SetEventTargetingPolicy(click_through ?
185+
aura::EventTargetingPolicy::kNone :
186+
aura::EventTargetingPolicy::kTargetAndDescendants);
163187
}
164188

165189
void InspectableWebContentsViewViews::ShowDevTools(bool activate) {

shell/browser/ui/views/inspectable_web_contents_view_views.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView,
3434
views::View* GetView() override;
3535
views::View* GetWebView() override;
3636
void SetCornerRadii(const gfx::RoundedCornersF& corner_radii) override;
37+
void SetClickThrough(bool click_through) override;
3738
void ShowDevTools(bool activate) override;
3839
void CloseDevTools() override;
3940
bool IsDevToolsViewShowing() override;

test/page_panel.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<html>
2+
<body style="background:white">
3+
<p>This is panel</p>
4+
<p><form>
5+
<button>Minimize</button>
6+
<button>Maximize</button>
7+
<button>Close</button>
8+
</form></p>
9+
</body>
10+
</html>
11+

0 commit comments

Comments
 (0)