Add Invalidate method to NativeWindow and add Mac implementation
authorGary Wilber <Spacetech326@gmail.com>
Tue, 14 Feb 2017 03:41:24 +0000 (19:41 -0800)
committerGary Wilber <Spacetech326@gmail.com>
Tue, 14 Feb 2017 03:41:24 +0000 (19:41 -0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/browser/native_window_views.h

index 5ae6186..c904373 100644 (file)
@@ -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();
     }
   }
 }
index 6f2d525..aa5e7e0 100644 (file)
@@ -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;
index 1860512..2beb55c 100644 (file)
@@ -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;
index b463d20..cef80ce 100644 (file)
@@ -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.
index 3270add..64ed061 100644 (file)
@@ -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();
index 7d983b8..a7f02fb 100644 (file)
@@ -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;