[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.
This commit is contained in:
Cheng Zhao 2013-07-08 10:48:59 +08:00
parent 525433905b
commit 7047e5167f
2 changed files with 50 additions and 6 deletions

View file

@ -4,6 +4,7 @@
#include "browser/native_window_win.h" #include "browser/native_window_win.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "common/options_switches.h" #include "common/options_switches.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
@ -16,8 +17,10 @@ NativeWindowWin::NativeWindowWin(content::WebContents* web_contents,
base::DictionaryValue* options) base::DictionaryValue* options)
: NativeWindow(web_contents, options), : NativeWindow(web_contents, options),
window_(new views::Widget), 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); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.delegate = this;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
window_->Init(params); window_->Init(params);
@ -152,12 +155,12 @@ gfx::Point NativeWindowWin::GetPosition() {
} }
void NativeWindowWin::SetTitle(const std::string& title) { void NativeWindowWin::SetTitle(const std::string& title) {
title_ = title; title_ = UTF8ToUTF16(title);
window_->UpdateWindowTitle(); window_->UpdateWindowTitle();
} }
std::string NativeWindowWin::GetTitle() { std::string NativeWindowWin::GetTitle() {
return title_; return UTF16ToUTF8(title_);
} }
void NativeWindowWin::FlashFrame(bool flash) { void NativeWindowWin::FlashFrame(bool flash) {
@ -185,6 +188,34 @@ void NativeWindowWin::HandleKeyboardEvent(
event.os_event.wParam, event.os_event.lParam); 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 // static
NativeWindow* NativeWindow::Create(content::WebContents* web_contents, NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
base::DictionaryValue* options) { base::DictionaryValue* options) {

View file

@ -5,9 +5,12 @@
#ifndef ATOM_BROWSER_NATIVE_WINDOW_WIN_H_ #ifndef ATOM_BROWSER_NATIVE_WINDOW_WIN_H_
#define ATOM_BROWSER_NATIVE_WINDOW_WIN_H_ #define ATOM_BROWSER_NATIVE_WINDOW_WIN_H_
#include "base/string16.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "browser/native_window.h" #include "browser/native_window.h"
#include "ui/gfx/size.h" #include "ui/gfx/size.h"
#include "ui/views/widget/widget_delegate.h"
namespace views { namespace views {
class WebView; class WebView;
@ -16,7 +19,8 @@ class Widget;
namespace atom { namespace atom {
class NativeWindowWin : public NativeWindow { class NativeWindowWin : public NativeWindow,
public views::WidgetDelegate {
public: public:
explicit NativeWindowWin(content::WebContents* web_contents, explicit NativeWindowWin(content::WebContents* web_contents,
base::DictionaryValue* options); base::DictionaryValue* options);
@ -57,17 +61,26 @@ class NativeWindowWin : public NativeWindow {
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
protected: protected:
// Implementations of content::WebContentsDelegate. // Overridden from content::WebContentsDelegate:
virtual void HandleKeyboardEvent( virtual void HandleKeyboardEvent(
content::WebContents*, content::WebContents*,
const content::NativeWebKeyboardEvent&) OVERRIDE; 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: private:
scoped_ptr<views::Widget> window_; scoped_ptr<views::Widget> window_;
views::WebView* web_view_; // managed by window_. views::WebView* web_view_; // managed by window_.
bool resizable_; bool resizable_;
std::string title_; string16 title_;
gfx::Size minimum_size_; gfx::Size minimum_size_;
gfx::Size maximum_size_; gfx::Size maximum_size_;