From 7047e5167fe878f564d7eb1c5da672db124f2efb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 8 Jul 2013 10:48:59 +0800 Subject: [PATCH] [Win] Implement simple delegate methods of Widget. From now on I'll use [Win], [Mac] and [GTK] to mark commits that only for each platform. --- browser/native_window_win.cc | 37 +++++++++++++++++++++++++++++++++--- browser/native_window_win.h | 19 +++++++++++++++--- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/browser/native_window_win.cc b/browser/native_window_win.cc index 9a2185a4bd3f..f437b022165d 100644 --- a/browser/native_window_win.cc +++ b/browser/native_window_win.cc @@ -4,6 +4,7 @@ #include "browser/native_window_win.h" +#include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "common/options_switches.h" #include "content/public/browser/native_web_keyboard_event.h" @@ -16,8 +17,10 @@ NativeWindowWin::NativeWindowWin(content::WebContents* web_contents, base::DictionaryValue* options) : NativeWindow(web_contents, options), window_(new views::Widget), - web_view_(new views::WebView(NULL)) { + web_view_(new views::WebView(NULL)), + resizable_(true) { views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); + params.delegate = this; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; window_->Init(params); @@ -152,12 +155,12 @@ gfx::Point NativeWindowWin::GetPosition() { } void NativeWindowWin::SetTitle(const std::string& title) { - title_ = title; + title_ = UTF8ToUTF16(title); window_->UpdateWindowTitle(); } std::string NativeWindowWin::GetTitle() { - return title_; + return UTF16ToUTF8(title_); } void NativeWindowWin::FlashFrame(bool flash) { @@ -185,6 +188,34 @@ void NativeWindowWin::HandleKeyboardEvent( event.os_event.wParam, event.os_event.lParam); } +bool NativeWindowWin::CanResize() const { + return resizable_; +} + +bool NativeWindowWin::CanMaximize() const { + return resizable_; +} + +string16 NativeWindowWin::GetWindowTitle() const { + return title_; +} + +bool NativeWindowWin::ShouldHandleSystemCommands() const { + return true; +} + +bool NativeWindowWin::ShouldShowWindowIcon() const { + return true; +} + +views::Widget* NativeWindowWin::GetWidget() { + return window_.get(); +} + +const views::Widget* NativeWindowWin::GetWidget() const { + return window_.get(); +} + // static NativeWindow* NativeWindow::Create(content::WebContents* web_contents, base::DictionaryValue* options) { diff --git a/browser/native_window_win.h b/browser/native_window_win.h index 97eab6b08902..68abaacda986 100644 --- a/browser/native_window_win.h +++ b/browser/native_window_win.h @@ -5,9 +5,12 @@ #ifndef ATOM_BROWSER_NATIVE_WINDOW_WIN_H_ #define ATOM_BROWSER_NATIVE_WINDOW_WIN_H_ +#include "base/string16.h" + #include "base/memory/scoped_ptr.h" #include "browser/native_window.h" #include "ui/gfx/size.h" +#include "ui/views/widget/widget_delegate.h" namespace views { class WebView; @@ -16,7 +19,8 @@ class Widget; namespace atom { -class NativeWindowWin : public NativeWindow { +class NativeWindowWin : public NativeWindow, + public views::WidgetDelegate { public: explicit NativeWindowWin(content::WebContents* web_contents, base::DictionaryValue* options); @@ -57,17 +61,26 @@ class NativeWindowWin : public NativeWindow { virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; protected: - // Implementations of content::WebContentsDelegate. + // Overridden from content::WebContentsDelegate: virtual void HandleKeyboardEvent( content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; + // Overridden from views::WidgetDelegate: + virtual bool CanResize() const OVERRIDE; + virtual bool CanMaximize() const OVERRIDE; + virtual string16 GetWindowTitle() const OVERRIDE; + virtual bool ShouldHandleSystemCommands() const OVERRIDE; + virtual bool ShouldShowWindowIcon() const OVERRIDE; + virtual views::Widget* GetWidget() OVERRIDE; + virtual const views::Widget* GetWidget() const OVERRIDE; + private: scoped_ptr window_; views::WebView* web_view_; // managed by window_. bool resizable_; - std::string title_; + string16 title_; gfx::Size minimum_size_; gfx::Size maximum_size_;