Avoid exposing data members to subclass

This commit is contained in:
Cheng Zhao 2015-08-05 12:46:32 +08:00
parent 438a5acc0f
commit 58b1172025
4 changed files with 53 additions and 46 deletions

View file

@ -522,6 +522,12 @@ void NativeWindow::NotifyWindowLeaveHtmlFullScreen() {
OnWindowLeaveHtmlFullScreen()); OnWindowLeaveHtmlFullScreen());
} }
void NativeWindow::NotifyWindowExecuteWindowsCommand(
const std::string& command) {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnExecuteWindowsCommand(command));
}
void NativeWindow::DevToolsFocused() { void NativeWindow::DevToolsFocused() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsFocus()); FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsFocus());
} }

View file

@ -205,11 +205,11 @@ class NativeWindow : public content::WebContentsObserver,
void NotifyWindowLeaveFullScreen(); void NotifyWindowLeaveFullScreen();
void NotifyWindowEnterHtmlFullScreen(); void NotifyWindowEnterHtmlFullScreen();
void NotifyWindowLeaveHtmlFullScreen(); void NotifyWindowLeaveHtmlFullScreen();
void NotifyWindowExecuteWindowsCommand(const std::string& command);
void AddObserver(NativeWindowObserver* obs) { void AddObserver(NativeWindowObserver* obs) {
observers_.AddObserver(obs); observers_.AddObserver(obs);
} }
void RemoveObserver(NativeWindowObserver* obs) { void RemoveObserver(NativeWindowObserver* obs) {
observers_.RemoveObserver(obs); observers_.RemoveObserver(obs);
} }
@ -219,7 +219,10 @@ class NativeWindow : public content::WebContentsObserver,
} }
bool has_frame() const { return has_frame_; } bool has_frame() const { return has_frame_; }
bool transparent() const { return transparent_; }
SkRegion* draggable_region() const { return draggable_region_.get(); } SkRegion* draggable_region() const { return draggable_region_.get(); }
bool enable_larger_than_screen() const { return enable_larger_than_screen_; }
gfx::ImageSkia icon() const { return icon_; }
void set_has_dialog_attached(bool has_dialog_attached) { void set_has_dialog_attached(bool has_dialog_attached) {
has_dialog_attached_ = has_dialog_attached; has_dialog_attached_ = has_dialog_attached;
@ -240,21 +243,6 @@ class NativeWindow : public content::WebContentsObserver,
void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override;
bool OnMessageReceived(const IPC::Message& message) override; bool OnMessageReceived(const IPC::Message& message) override;
// Whether window has standard frame.
bool has_frame_;
// Whether window is transparent.
bool transparent_;
// Whether window can be resized larger than screen.
bool enable_larger_than_screen_;
// Window icon.
gfx::ImageSkia icon_;
// Observers of this window.
ObserverList<NativeWindowObserver> observers_;
private: private:
// Called when the window needs to update its draggable region. // Called when the window needs to update its draggable region.
void UpdateDraggableRegions( void UpdateDraggableRegions(
@ -271,6 +259,22 @@ class NativeWindow : public content::WebContentsObserver,
const SkBitmap& bitmap, const SkBitmap& bitmap,
content::ReadbackResponse response); content::ReadbackResponse response);
// Whether window has standard frame.
bool has_frame_;
// Whether window is transparent.
bool transparent_;
// For custom drag, the whole window is non-draggable and the draggable region
// has to been explicitly provided.
scoped_ptr<SkRegion> draggable_region_; // used in custom drag.
// Whether window can be resized larger than screen.
bool enable_larger_than_screen_;
// Window icon.
gfx::ImageSkia icon_;
// The windows has been closed. // The windows has been closed.
bool is_closed_; bool is_closed_;
@ -301,9 +305,8 @@ class NativeWindow : public content::WebContentsObserver,
// The page this window is viewing. // The page this window is viewing.
brightray::InspectableWebContents* inspectable_web_contents_; brightray::InspectableWebContents* inspectable_web_contents_;
// For custom drag, the whole window is non-draggable and the draggable region // Observers of this window.
// has to been explicitly provided. ObserverList<NativeWindowObserver> observers_;
scoped_ptr<SkRegion> draggable_region_; // used in custom drag.
base::WeakPtrFactory<NativeWindow> weak_factory_; base::WeakPtrFactory<NativeWindow> weak_factory_;

View file

@ -340,7 +340,7 @@ NativeWindowMac::NativeWindowMac(
NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask | NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask | NSResizableWindowMask; NSMiniaturizableWindowMask | NSResizableWindowMask;
if (!useStandardWindow || transparent_ || !has_frame_) { if (!useStandardWindow || transparent() || !has_frame()) {
styleMask |= NSTexturedBackgroundWindowMask; styleMask |= NSTexturedBackgroundWindowMask;
} }
@ -350,12 +350,12 @@ NativeWindowMac::NativeWindowMac(
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:YES]); defer:YES]);
[window_ setShell:this]; [window_ setShell:this];
[window_ setEnableLargerThanScreen:enable_larger_than_screen_]; [window_ setEnableLargerThanScreen:enable_larger_than_screen()];
window_delegate_.reset([[AtomNSWindowDelegate alloc] initWithShell:this]); window_delegate_.reset([[AtomNSWindowDelegate alloc] initWithShell:this]);
[window_ setDelegate:window_delegate_]; [window_ setDelegate:window_delegate_];
if (transparent_) { if (transparent()) {
// Make window has transparent background. // Make window has transparent background.
[window_ setOpaque:NO]; [window_ setOpaque:NO];
[window_ setHasShadow:NO]; [window_ setHasShadow:NO];
@ -363,7 +363,7 @@ NativeWindowMac::NativeWindowMac(
} }
// Remove non-transparent corners, see http://git.io/vfonD. // Remove non-transparent corners, see http://git.io/vfonD.
if (!has_frame_) if (!has_frame())
[window_ setOpaque:NO]; [window_ setOpaque:NO];
// We will manage window's lifetime ourselves. // We will manage window's lifetime ourselves.
@ -372,7 +372,7 @@ NativeWindowMac::NativeWindowMac(
// On OS X the initial window size doesn't include window frame. // On OS X the initial window size doesn't include window frame.
bool use_content_size = false; bool use_content_size = false;
options.Get(switches::kUseContentSize, &use_content_size); options.Get(switches::kUseContentSize, &use_content_size);
if (!has_frame_ || !use_content_size) if (!has_frame() || !use_content_size)
SetSize(gfx::Size(width, height)); SetSize(gfx::Size(width, height));
// Enable the NSView to accept first mouse event. // Enable the NSView to accept first mouse event.
@ -509,7 +509,7 @@ gfx::Rect NativeWindowMac::GetBounds() {
} }
void NativeWindowMac::SetContentSize(const gfx::Size& size) { void NativeWindowMac::SetContentSize(const gfx::Size& size) {
if (!has_frame_) { if (!has_frame()) {
SetSize(size); SetSize(size);
return; return;
} }
@ -527,7 +527,7 @@ void NativeWindowMac::SetContentSize(const gfx::Size& size) {
} }
gfx::Size NativeWindowMac::GetContentSize() { gfx::Size NativeWindowMac::GetContentSize() {
if (!has_frame_) if (!has_frame())
return GetSize(); return GetSize();
NSRect bounds = [[window_ contentView] bounds]; NSRect bounds = [[window_ contentView] bounds];
@ -588,7 +588,7 @@ void NativeWindowMac::Center() {
void NativeWindowMac::SetTitle(const std::string& title) { void NativeWindowMac::SetTitle(const std::string& title) {
// We don't want the title to show in transparent window. // We don't want the title to show in transparent window.
if (transparent_) if (transparent())
return; return;
[window_ setTitle:base::SysUTF8ToNSString(title)]; [window_ setTitle:base::SysUTF8ToNSString(title)];
@ -779,7 +779,7 @@ void NativeWindowMac::HandleKeyboardEvent(
void NativeWindowMac::InstallView() { void NativeWindowMac::InstallView() {
NSView* view = inspectable_web_contents()->GetView()->GetNativeView(); NSView* view = inspectable_web_contents()->GetView()->GetNativeView();
if (has_frame_) { if (has_frame()) {
// Add layer with white background for the contents view. // Add layer with white background for the contents view.
base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]); base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]);
[layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; [layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];

View file

@ -232,7 +232,7 @@ NativeWindowViews::NativeWindowViews(
options.Get(switches::kResizable, &resizable_); options.Get(switches::kResizable, &resizable_);
#endif #endif
if (enable_larger_than_screen_) if (enable_larger_than_screen())
// We need to set a default maximum window size here otherwise Windows // We need to set a default maximum window size here otherwise Windows
// will not allow us to resize the window larger than scree. // will not allow us to resize the window larger than scree.
// Setting directly to INT_MAX somehow doesn't work, so we just devide // Setting directly to INT_MAX somehow doesn't work, so we just devide
@ -252,9 +252,9 @@ NativeWindowViews::NativeWindowViews(
params.bounds = bounds; params.bounds = bounds;
params.delegate = this; params.delegate = this;
params.type = views::Widget::InitParams::TYPE_WINDOW; params.type = views::Widget::InitParams::TYPE_WINDOW;
params.remove_standard_frame = !has_frame_; params.remove_standard_frame = !has_frame();
if (transparent_) if (transparent())
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
#if defined(USE_X11) #if defined(USE_X11)
@ -312,24 +312,24 @@ NativeWindowViews::NativeWindowViews(
set_background(views::Background::CreateStandardPanelBackground()); set_background(views::Background::CreateStandardPanelBackground());
AddChildView(web_view_); AddChildView(web_view_);
if (has_frame_ && if (has_frame() &&
options.Get(switches::kUseContentSize, &use_content_size_) && options.Get(switches::kUseContentSize, &use_content_size_) &&
use_content_size_) use_content_size_)
bounds = ContentBoundsToWindowBounds(bounds); bounds = ContentBoundsToWindowBounds(bounds);
#if defined(OS_WIN) #if defined(OS_WIN)
if (!has_frame_) { if (!has_frame()) {
// Set Window style so that we get a minimize and maximize animation when // Set Window style so that we get a minimize and maximize animation when
// frameless. // frameless.
DWORD frame_style = WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | DWORD frame_style = WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX |
WS_CAPTION; WS_CAPTION;
// We should not show a frame for transparent window. // We should not show a frame for transparent window.
if (transparent_) if (transparent())
frame_style &= ~(WS_THICKFRAME | WS_CAPTION); frame_style &= ~(WS_THICKFRAME | WS_CAPTION);
::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, frame_style); ::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, frame_style);
} }
if (transparent_) { if (transparent()) {
// Transparent window on Windows has to have WS_EX_COMPOSITED style. // Transparent window on Windows has to have WS_EX_COMPOSITED style.
LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE); LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
ex_style |= WS_EX_COMPOSITED; ex_style |= WS_EX_COMPOSITED;
@ -339,14 +339,14 @@ NativeWindowViews::NativeWindowViews(
// TODO(zcbenz): This was used to force using native frame on Windows 2003, we // TODO(zcbenz): This was used to force using native frame on Windows 2003, we
// should check whether setting it in InitParams can work. // should check whether setting it in InitParams can work.
if (has_frame_) { if (has_frame()) {
window_->set_frame_type(views::Widget::FrameType::FRAME_TYPE_FORCE_NATIVE); window_->set_frame_type(views::Widget::FrameType::FRAME_TYPE_FORCE_NATIVE);
window_->FrameTypeChanged(); window_->FrameTypeChanged();
} }
// The given window is most likely not rectangular since it uses // The given window is most likely not rectangular since it uses
// transparency and has no standard frame, don't show a shadow for it. // transparency and has no standard frame, don't show a shadow for it.
if (transparent_ && !has_frame_) if (transparent() && !has_frame())
wm::SetShadowType(GetNativeWindow(), wm::SHADOW_TYPE_NONE); wm::SetShadowType(GetNativeWindow(), wm::SHADOW_TYPE_NONE);
window_->UpdateWindowIcon(); window_->UpdateWindowIcon();
@ -469,7 +469,7 @@ gfx::Rect NativeWindowViews::GetBounds() {
} }
void NativeWindowViews::SetContentSize(const gfx::Size& size) { void NativeWindowViews::SetContentSize(const gfx::Size& size) {
if (!has_frame_) { if (!has_frame()) {
NativeWindow::SetSize(size); NativeWindow::SetSize(size);
return; return;
} }
@ -480,7 +480,7 @@ void NativeWindowViews::SetContentSize(const gfx::Size& size) {
} }
gfx::Size NativeWindowViews::GetContentSize() { gfx::Size NativeWindowViews::GetContentSize() {
if (!has_frame_) if (!has_frame())
return GetSize(); return GetSize();
gfx::Size content_size = gfx::Size content_size =
@ -628,7 +628,7 @@ void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
#endif #endif
// Do not show menu bar in frameless window. // Do not show menu bar in frameless window.
if (!has_frame_) if (!has_frame())
return; return;
if (!menu_bar_) { if (!menu_bar_) {
@ -812,7 +812,7 @@ bool NativeWindowViews::ShouldHandleSystemCommands() const {
} }
gfx::ImageSkia NativeWindowViews::GetWindowAppIcon() { gfx::ImageSkia NativeWindowViews::GetWindowAppIcon() {
return icon_; return icon();
} }
gfx::ImageSkia NativeWindowViews::GetWindowIcon() { gfx::ImageSkia NativeWindowViews::GetWindowIcon() {
@ -840,7 +840,7 @@ bool NativeWindowViews::ShouldDescendIntoChildForEventHandling(
return false; return false;
// And the events on border for dragging resizable frameless window. // And the events on border for dragging resizable frameless window.
if (!has_frame_ && CanResize()) { if (!has_frame() && CanResize()) {
FramelessView* frame = static_cast<FramelessView*>( FramelessView* frame = static_cast<FramelessView*>(
window_->non_client_view()->frame_view()); window_->non_client_view()->frame_view());
return frame->ResizingBorderHitTest(location) == HTNOWHERE; return frame->ResizingBorderHitTest(location) == HTNOWHERE;
@ -860,7 +860,7 @@ views::NonClientFrameView* NativeWindowViews::CreateNonClientFrameView(
frame_view->Init(this, widget); frame_view->Init(this, widget);
return frame_view; return frame_view;
#else #else
if (has_frame_) { if (has_frame()) {
return new NativeFrameView(this, widget); return new NativeFrameView(this, widget);
} else { } else {
FramelessView* frame_view = new FramelessView; FramelessView* frame_view = new FramelessView;
@ -892,9 +892,7 @@ bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
NotifyWindowMaximize(); NotifyWindowMaximize();
} else { } else {
std::string command = AppCommandToString(command_id); std::string command = AppCommandToString(command_id);
FOR_EACH_OBSERVER(NativeWindowObserver, NotifyWindowExecuteWindowsCommand(command);
observers_,
OnExecuteWindowsCommand(command));
} }
return false; return false;
} }