]> khamidou — GitHub mirrors - electron.git/commitdiff
[Win] Provide ClientView implementation.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 8 Jul 2013 09:00:42 +0000 (17:00 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 8 Jul 2013 09:00:42 +0000 (17:00 +0800)
browser/native_window_win.cc
browser/native_window_win.h

index f437b022165dd274967f40cd1158648944f825fb..5f31ed12f401ad92c2e4688a7e6920456ad4972f 100644 (file)
 #include "content/public/browser/native_web_keyboard_event.h"
 #include "ui/views/controls/webview/webview.h"
 #include "ui/views/widget/widget.h"
+#include "ui/views/window/client_view.h"
 
 namespace atom {
 
+namespace {
+
+class NativeWindowClientView : public views::ClientView {
+ public:
+  NativeWindowClientView(views::Widget* widget,
+                         views::View* contents_view,
+                         NativeWindowWin* shell)
+      : views::ClientView(widget, contents_view),
+        shell_(shell) {
+  }
+  virtual ~NativeWindowClientView() {}
+
+  virtual bool CanClose() OVERRIDE {
+    shell_->CloseWebContents();
+    return false;
+  }
+
+ private:
+  NativeWindowWin* shell_;
+};
+
+
+}  // namespace
+
 NativeWindowWin::NativeWindowWin(content::WebContents* web_contents,
                                  base::DictionaryValue* options)
     : NativeWindow(web_contents, options),
@@ -32,7 +57,6 @@ NativeWindowWin::NativeWindowWin(content::WebContents* web_contents,
   window_->CenterWindow(size);
 
   web_view_->SetWebContents(web_contents);
-  window_->SetContentsView(web_view_);
 }
 
 NativeWindowWin::~NativeWindowWin() {
@@ -216,6 +240,10 @@ const views::Widget* NativeWindowWin::GetWidget() const {
   return window_.get();
 }
 
+views::ClientView* NativeWindowWin::CreateClientView(views::Widget* widget) {
+  return new NativeWindowClientView(widget, web_view_, this);
+}
+
 // static
 NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
                                    base::DictionaryValue* options) {
index 68abaacda98658ba870e33add9bdf7fe851aa970..22c6d35adb4056c4847c367a6ce2031bcdf52d4f 100644 (file)
@@ -74,6 +74,7 @@ class NativeWindowWin : public NativeWindow,
   virtual bool ShouldShowWindowIcon() const OVERRIDE;
   virtual views::Widget* GetWidget() OVERRIDE;
   virtual const views::Widget* GetWidget() const OVERRIDE;
+  virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
 
  private:
   scoped_ptr<views::Widget> window_;