From 148898fb757ef5ebd165f82e12fa95c2a3d04c27 Mon Sep 17 00:00:00 2001 From: Gary Wilber Date: Tue, 7 Feb 2017 23:03:42 -0800 Subject: [PATCH 1/8] Implement invalidate for non-offscreen mode --- atom/browser/api/atom_api_web_contents.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 9d5c8f8684d..3605f806aed 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1489,13 +1489,20 @@ int WebContents::GetFrameRate() const { } void WebContents::Invalidate() { - if (!IsOffScreen()) - return; - - auto* osr_rwhv = static_cast( - web_contents()->GetRenderWidgetHostView()); - if (osr_rwhv) - osr_rwhv->Invalidate(); + if (IsOffScreen()) { + auto* osr_rwhv = static_cast( + web_contents()->GetRenderWidgetHostView()); + if (osr_rwhv) + osr_rwhv->Invalidate(); + } + else { + const auto ownerWindow = owner_window(); + const auto nativeWindow = ownerWindow ? ownerWindow->GetNativeWindow() : nullptr; + if (nativeWindow) { + const gfx::Rect& bounds = nativeWindow->bounds(); + nativeWindow->SchedulePaintInRect(gfx::Rect(0, 0, bounds.width(), bounds.height())); + } + } } v8::Local WebContents::GetWebPreferences(v8::Isolate* isolate) { From ed44b32ff58348275b3e7c2d4888e9ddf31aa4d2 Mon Sep 17 00:00:00 2001 From: Gary Wilber Date: Tue, 7 Feb 2017 23:08:03 -0800 Subject: [PATCH 2/8] Convert indentation to spaces --- atom/browser/api/atom_api_web_contents.cc | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 3605f806aed..a5384f83d2d 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1489,20 +1489,20 @@ int WebContents::GetFrameRate() const { } void WebContents::Invalidate() { - if (IsOffScreen()) { - auto* osr_rwhv = static_cast( - web_contents()->GetRenderWidgetHostView()); - if (osr_rwhv) - osr_rwhv->Invalidate(); - } - else { - const auto ownerWindow = owner_window(); - const auto nativeWindow = ownerWindow ? ownerWindow->GetNativeWindow() : nullptr; - if (nativeWindow) { - const gfx::Rect& bounds = nativeWindow->bounds(); - nativeWindow->SchedulePaintInRect(gfx::Rect(0, 0, bounds.width(), bounds.height())); - } - } + if (IsOffScreen()) { + auto* osr_rwhv = static_cast( + web_contents()->GetRenderWidgetHostView()); + if (osr_rwhv) + osr_rwhv->Invalidate(); + } + else { + const auto ownerWindow = owner_window(); + const auto nativeWindow = ownerWindow ? ownerWindow->GetNativeWindow() : nullptr; + if (nativeWindow) { + const gfx::Rect& bounds = nativeWindow->bounds(); + nativeWindow->SchedulePaintInRect(gfx::Rect(0, 0, bounds.width(), bounds.height())); + } + } } v8::Local WebContents::GetWebPreferences(v8::Isolate* isolate) { From 11e1f6b56c15a7ea1edf964bbbc27e8c2e734627 Mon Sep 17 00:00:00 2001 From: Gary Wilber Date: Wed, 8 Feb 2017 00:05:16 -0800 Subject: [PATCH 3/8] Fix lint errors --- atom/browser/api/atom_api_web_contents.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index a5384f83d2d..5ae6186a04e 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1494,13 +1494,14 @@ void WebContents::Invalidate() { web_contents()->GetRenderWidgetHostView()); if (osr_rwhv) osr_rwhv->Invalidate(); - } - else { + } else { const auto ownerWindow = owner_window(); - const auto nativeWindow = ownerWindow ? ownerWindow->GetNativeWindow() : nullptr; + const auto nativeWindow = ownerWindow ? ownerWindow->GetNativeWindow() : + nullptr; if (nativeWindow) { const gfx::Rect& bounds = nativeWindow->bounds(); - nativeWindow->SchedulePaintInRect(gfx::Rect(0, 0, bounds.width(), bounds.height())); + nativeWindow->SchedulePaintInRect( + gfx::Rect(0, 0, bounds.width(), bounds.height())); } } } From f19924bcb04a2e5b690edc271152f8bce5367ec6 Mon Sep 17 00:00:00 2001 From: Gary Wilber Date: Mon, 13 Feb 2017 19:41:24 -0800 Subject: [PATCH 4/8] Add Invalidate method to NativeWindow and add Mac implementation --- atom/browser/api/atom_api_web_contents.cc | 8 ++------ atom/browser/native_window.h | 1 + atom/browser/native_window_mac.h | 1 + atom/browser/native_window_mac.mm | 5 +++++ atom/browser/native_window_views.cc | 6 ++++++ atom/browser/native_window_views.h | 1 + 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 5ae6186a04e..c90437372d7 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1496,12 +1496,8 @@ void WebContents::Invalidate() { osr_rwhv->Invalidate(); } else { const auto ownerWindow = owner_window(); - const auto nativeWindow = ownerWindow ? ownerWindow->GetNativeWindow() : - nullptr; - if (nativeWindow) { - const gfx::Rect& bounds = nativeWindow->bounds(); - nativeWindow->SchedulePaintInRect( - gfx::Rect(0, 0, bounds.width(), bounds.height())); + if (ownerWindow) { + ownerWindow->Invalidate(); } } } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 6f2d5254697..aa5e7e0c715 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -124,6 +124,7 @@ class NativeWindow : public base::SupportsUserData, std::string* error = nullptr) = 0; virtual bool IsAlwaysOnTop() = 0; virtual void Center() = 0; + virtual void Invalidate() = 0; virtual void SetTitle(const std::string& title) = 0; virtual std::string GetTitle() = 0; virtual void FlashFrame(bool flash) = 0; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 186051200a3..2beb55c0296 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -71,6 +71,7 @@ class NativeWindowMac : public NativeWindow, int relativeLevel, std::string* error) override; bool IsAlwaysOnTop() override; void Center() override; + void Invalidate() override; void SetTitle(const std::string& title) override; std::string GetTitle() override; void FlashFrame(bool flash) override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index b463d2067c5..cef80ceabf6 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -1101,6 +1101,11 @@ void NativeWindowMac::Center() { [window_ center]; } +void NativeWindowMac::Invalidate() { + [window_ flushWindow]; + [[window_ contentView] setNeedsDisplay:TRUE]; +} + void NativeWindowMac::SetTitle(const std::string& title) { // For macOS <= 10.9, the setTitleVisibility API is not available, we have // to avoid calling setTitle for frameless window. diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 3270add5835..64ed0611f3b 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -695,6 +695,12 @@ void NativeWindowViews::Center() { window_->CenterWindow(GetSize()); } +void NativeWindowViews::Invalidate() { + const gfx::Rect& bounds = GetBounds(); + window_->SchedulePaintInRect( + gfx::Rect(0, 0, bounds.width(), bounds.height())); +} + void NativeWindowViews::SetTitle(const std::string& title) { title_ = title; window_->UpdateWindowTitle(); diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 7d983b89a57..a7f02fb2727 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -90,6 +90,7 @@ class NativeWindowViews : public NativeWindow, int relativeLevel, std::string* error) override; bool IsAlwaysOnTop() override; void Center() override; + void Invalidate() override; void SetTitle(const std::string& title) override; std::string GetTitle() override; void FlashFrame(bool flash) override; From 82f452568cfd7f66df210079b4686a8a1382d5dc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 14 Feb 2017 11:09:15 -0800 Subject: [PATCH 5/8] :art: Minor formatting tweaks --- atom/browser/api/atom_api_web_contents.cc | 3 +-- atom/browser/native_window_mac.mm | 2 +- atom/browser/native_window_views.cc | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index c90437372d7..bd57bc217f6 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1496,9 +1496,8 @@ void WebContents::Invalidate() { osr_rwhv->Invalidate(); } else { const auto ownerWindow = owner_window(); - if (ownerWindow) { + if (ownerWindow) ownerWindow->Invalidate(); - } } } diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index cef80ceabf6..8b1eff27c43 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -1103,7 +1103,7 @@ void NativeWindowMac::Center() { void NativeWindowMac::Invalidate() { [window_ flushWindow]; - [[window_ contentView] setNeedsDisplay:TRUE]; + [[window_ contentView] setNeedsDisplay:YES]; } void NativeWindowMac::SetTitle(const std::string& title) { diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 64ed0611f3b..4b64367bdfd 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -697,8 +697,7 @@ void NativeWindowViews::Center() { void NativeWindowViews::Invalidate() { const gfx::Rect& bounds = GetBounds(); - window_->SchedulePaintInRect( - gfx::Rect(0, 0, bounds.width(), bounds.height())); + window_->SchedulePaintInRect(gfx::Rect(GetBounds().size())); } void NativeWindowViews::SetTitle(const std::string& title) { From 5cb664868636e95f6acf4689cac4203f00dc3667 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 14 Feb 2017 11:12:30 -0800 Subject: [PATCH 6/8] Use underscore variable name for consistency --- atom/browser/api/atom_api_web_contents.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index bd57bc217f6..5834e4c7b33 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1495,9 +1495,9 @@ void WebContents::Invalidate() { if (osr_rwhv) osr_rwhv->Invalidate(); } else { - const auto ownerWindow = owner_window(); - if (ownerWindow) - ownerWindow->Invalidate(); + const auto owner_window = owner_window(); + if (owner_window) + owner_window->Invalidate(); } } From 643cb5d6def5ef7e2864424bbb806696b36a5f79 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 14 Feb 2017 11:13:23 -0800 Subject: [PATCH 7/8] Remove unused variable --- atom/browser/native_window_views.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 4b64367bdfd..771caf583de 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -696,7 +696,6 @@ void NativeWindowViews::Center() { } void NativeWindowViews::Invalidate() { - const gfx::Rect& bounds = GetBounds(); window_->SchedulePaintInRect(gfx::Rect(GetBounds().size())); } From 52d989f9081cd72e6f815a26551be79a81e15537 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 14 Feb 2017 11:17:39 -0800 Subject: [PATCH 8/8] Update docs for non-offscreen invalidate --- docs/api/web-contents.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 38e5808594e..7c636aee394 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -1210,6 +1210,8 @@ Returns `Integer` - If *offscreen rendering* is enabled returns the current fram #### `contents.invalidate()` +Schedules a full repaint of the window this web contents is in. + If *offscreen rendering* is enabled invalidates the frame and generates a new one through the `'paint'` event.