From 727cd68ceec7ef869674c4a5b92683fea433478d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 25 Apr 2018 15:59:16 +0900 Subject: [PATCH] refactor: Use widget() instead of window_ --- atom/browser/native_window_views.cc | 108 ++++++++++++++-------------- atom/browser/native_window_views.h | 4 +- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 5a0a09493a..503fdefa80 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -120,7 +120,7 @@ class NativeWindowClientView : public views::ClientView { NativeWindowViews::NativeWindowViews(const mate::Dictionary& options, NativeWindow* parent) : NativeWindow(options, parent), - window_(new views::Widget), + widget_(new views::Widget), content_view_(nullptr), focused_view_(nullptr), menu_bar_autohide_(false), @@ -171,7 +171,7 @@ NativeWindowViews::NativeWindowViews(const mate::Dictionary& options, gfx::Rect bounds(0, 0, width, height); widget_size_ = bounds.size(); - window_->AddObserver(this); + widget()->AddObserver(this); views::Widget::InitParams params; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; @@ -196,9 +196,9 @@ NativeWindowViews::NativeWindowViews(const mate::Dictionary& options, if (parent) params.parent = parent->GetNativeWindow(); - params.native_widget = new AtomDesktopNativeWidgetAura(window_.get()); + params.native_widget = new AtomDesktopNativeWidgetAura(widget()); atom_desktop_window_tree_host_win_ = new AtomDesktopWindowTreeHostWin( - this, window_.get(), + this, widget(), static_cast(params.native_widget)); params.desktop_window_tree_host = atom_desktop_window_tree_host_win_; #elif defined(USE_X11) @@ -210,7 +210,7 @@ NativeWindowViews::NativeWindowViews(const mate::Dictionary& options, params.wm_class_class = name; #endif - window_->Init(params); + widget()->Init(params); bool fullscreen = false; options.Get(options::kFullscreen, &fullscreen); @@ -290,8 +290,8 @@ NativeWindowViews::NativeWindowViews(const mate::Dictionary& options, if (has_frame()) { // TODO(zcbenz): This was used to force using native frame on Windows 2003, // we should check whether setting it in InitParams can work. - window_->set_frame_type(views::Widget::FrameType::FRAME_TYPE_FORCE_NATIVE); - window_->FrameTypeChanged(); + widget()->set_frame_type(views::Widget::FrameType::FRAME_TYPE_FORCE_NATIVE); + widget()->FrameTypeChanged(); #if defined(OS_WIN) // thickFrame also works for normal window. if (!thick_frame_) @@ -305,7 +305,7 @@ NativeWindowViews::NativeWindowViews(const mate::Dictionary& options, use_content_size_) size = ContentBoundsToWindowBounds(gfx::Rect(size)).size(); - window_->CenterWindow(size); + widget()->CenterWindow(size); #if defined(OS_WIN) // Save initial window state. @@ -318,7 +318,7 @@ NativeWindowViews::NativeWindowViews(const mate::Dictionary& options, } NativeWindowViews::~NativeWindowViews() { - window_->RemoveObserver(this); + widget()->RemoveObserver(this); #if defined(OS_WIN) // Disable mouse forwarding to relinquish resources, should any be held. @@ -348,11 +348,11 @@ void NativeWindowViews::Close() { return; } - window_->Close(); + widget()->Close(); } void NativeWindowViews::CloseImmediately() { - window_->CloseNow(); + widget()->CloseNow(); } void NativeWindowViews::Focus(bool focus) { @@ -361,22 +361,22 @@ void NativeWindowViews::Focus(bool focus) { return; if (focus) { - window_->Activate(); + widget()->Activate(); } else { - window_->Deactivate(); + widget()->Deactivate(); } } bool NativeWindowViews::IsFocused() { - return window_->IsActive(); + return widget()->IsActive(); } void NativeWindowViews::Show() { if (is_modal() && NativeWindow::parent() && - !window_->native_widget_private()->IsVisible()) + !widget()->native_widget_private()->IsVisible()) static_cast(NativeWindow::parent())->SetEnabled(false); - window_->native_widget_private()->ShowWithWindowState(GetRestoredState()); + widget()->native_widget_private()->ShowWithWindowState(GetRestoredState()); NotifyWindowShow(); @@ -387,7 +387,7 @@ void NativeWindowViews::Show() { } void NativeWindowViews::ShowInactive() { - window_->ShowInactive(); + widget()->ShowInactive(); NotifyWindowShow(); @@ -401,7 +401,7 @@ void NativeWindowViews::Hide() { if (is_modal() && NativeWindow::parent()) static_cast(NativeWindow::parent())->SetEnabled(true); - window_->Hide(); + widget()->Hide(); NotifyWindowHide(); @@ -412,7 +412,7 @@ void NativeWindowViews::Hide() { } bool NativeWindowViews::IsVisible() { - return window_->IsVisible(); + return widget()->IsVisible(); } bool NativeWindowViews::IsEnabled() { @@ -463,9 +463,9 @@ void NativeWindowViews::Maximize() { #endif if (IsVisible()) - window_->Maximize(); + widget()->Maximize(); else - window_->native_widget_private()->ShowWithWindowState( + widget()->native_widget_private()->ShowWithWindowState( ui::SHOW_STATE_MAXIMIZED); } @@ -477,27 +477,27 @@ void NativeWindowViews::Unmaximize() { } #endif - window_->Restore(); + widget()->Restore(); } bool NativeWindowViews::IsMaximized() { - return window_->IsMaximized(); + return widget()->IsMaximized(); } void NativeWindowViews::Minimize() { if (IsVisible()) - window_->Minimize(); + widget()->Minimize(); else - window_->native_widget_private()->ShowWithWindowState( + widget()->native_widget_private()->ShowWithWindowState( ui::SHOW_STATE_MINIMIZED); } void NativeWindowViews::Restore() { - window_->Restore(); + widget()->Restore(); } bool NativeWindowViews::IsMinimized() { - return window_->IsMinimized(); + return widget()->IsMinimized(); } void NativeWindowViews::SetFullScreen(bool fullscreen) { @@ -532,19 +532,19 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) { // We set the new value after notifying, so we can handle the size event // correctly. - window_->SetFullscreen(fullscreen); + widget()->SetFullscreen(fullscreen); // If restoring from fullscreen and the window isn't visible, force visible, // else a non-responsive window shell could be rendered. // (this situation may arise when app starts with fullscreen: true) - // Note: the following must be after "window_->SetFullscreen(fullscreen);" + // Note: the following must be after "widget()->SetFullscreen(fullscreen);" if (leaving_fullscreen && !IsVisible()) FlipWindowStyle(GetAcceleratedWidget(), true, WS_VISIBLE); #else if (IsVisible()) - window_->SetFullscreen(fullscreen); + widget()->SetFullscreen(fullscreen); else if (fullscreen) - window_->native_widget_private()->ShowWithWindowState( + widget()->native_widget_private()->ShowWithWindowState( ui::SHOW_STATE_FULLSCREEN); // Auto-hide menubar when in fullscreen. @@ -556,7 +556,7 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) { } bool NativeWindowViews::IsFullscreen() const { - return window_->IsFullscreen(); + return widget()->IsFullscreen(); } void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate) { @@ -569,16 +569,16 @@ void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate) { } #endif - window_->SetBounds(bounds); + widget()->SetBounds(bounds); } gfx::Rect NativeWindowViews::GetBounds() { #if defined(OS_WIN) if (IsMinimized()) - return window_->GetRestoredBounds(); + return widget()->GetRestoredBounds(); #endif - return window_->GetWindowBoundsInScreen(); + return widget()->GetWindowBoundsInScreen(); } gfx::Rect NativeWindowViews::GetContentBounds() { @@ -605,8 +605,8 @@ void NativeWindowViews::SetContentSizeConstraints( #endif // widget_delegate() is only available after Init() is called, we make use of // this to determine whether native widget has initialized. - if (window_ && window_->widget_delegate()) - window_->OnSizeConstraintsChanged(); + if (widget() && widget()->widget_delegate()) + widget()->OnSizeConstraintsChanged(); #if defined(OS_WIN) || defined(USE_X11) if (resizable_) old_size_constraints_ = size_constraints; @@ -739,24 +739,24 @@ void NativeWindowViews::SetAlwaysOnTop(bool top, const std::string& level, int relativeLevel, std::string* error) { - window_->SetAlwaysOnTop(top); + widget()->SetAlwaysOnTop(top); } bool NativeWindowViews::IsAlwaysOnTop() { - return window_->IsAlwaysOnTop(); + return widget()->IsAlwaysOnTop(); } void NativeWindowViews::Center() { - window_->CenterWindow(GetSize()); + widget()->CenterWindow(GetSize()); } void NativeWindowViews::Invalidate() { - window_->SchedulePaintInRect(gfx::Rect(GetBounds().size())); + widget()->SchedulePaintInRect(gfx::Rect(GetBounds().size())); } void NativeWindowViews::SetTitle(const std::string& title) { title_ = title; - window_->UpdateWindowTitle(); + widget()->UpdateWindowTitle(); } std::string NativeWindowViews::GetTitle() { @@ -776,7 +776,7 @@ void NativeWindowViews::FlashFrame(bool flash) { return; } #endif - window_->FlashFrame(flash); + widget()->FlashFrame(flash); } void NativeWindowViews::SetSkipTaskbar(bool skip) { @@ -1018,11 +1018,11 @@ void NativeWindowViews::SetParentWindow(NativeWindow* parent) { } gfx::NativeView NativeWindowViews::GetNativeView() const { - return window_->GetNativeView(); + return widget()->GetNativeView(); } gfx::NativeWindow NativeWindowViews::GetNativeWindow() const { - return window_->GetNativeWindow(); + return widget()->GetNativeWindow(); } void NativeWindowViews::SetProgressBar(double progress, @@ -1076,7 +1076,7 @@ bool NativeWindowViews::IsMenuBarVisible() { } void NativeWindowViews::SetVisibleOnAllWorkspaces(bool visible) { - window_->SetVisibleOnAllWorkspaces(visible); + widget()->SetVisibleOnAllWorkspaces(visible); } bool NativeWindowViews::IsVisibleOnAllWorkspaces() { @@ -1107,7 +1107,7 @@ gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds( gfx::Rect dpi_bounds = display::win::ScreenWin::DIPToScreenRect(hwnd, bounds); window_bounds = display::win::ScreenWin::ScreenToDIPRect( hwnd, - window_->non_client_view()->GetWindowBoundsForClientBounds(dpi_bounds)); + widget()->non_client_view()->GetWindowBoundsForClientBounds(dpi_bounds)); #endif if (menu_bar_ && menu_bar_visible_) { @@ -1171,9 +1171,9 @@ void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) { } #endif -void NativeWindowViews::OnWidgetActivationChanged(views::Widget* widget, +void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget, bool active) { - if (widget != window_.get()) + if (changed_widget != widget()) return; // Post the notification to next tick. @@ -1190,9 +1190,9 @@ void NativeWindowViews::OnWidgetActivationChanged(views::Widget* widget, menu_bar_alt_pressed_ = false; } -void NativeWindowViews::OnWidgetBoundsChanged(views::Widget* widget, +void NativeWindowViews::OnWidgetBoundsChanged(views::Widget* changed_widget, const gfx::Rect& bounds) { - if (widget != window_.get()) + if (changed_widget != widget()) return; // Note: We intentionally use `GetBounds()` instead of `bounds` to properly @@ -1265,11 +1265,11 @@ bool NativeWindowViews::ShouldHandleSystemCommands() const { } views::Widget* NativeWindowViews::GetWidget() { - return window_.get(); + return widget(); } const views::Widget* NativeWindowViews::GetWidget() const { - return window_.get(); + return widget(); } views::View* NativeWindowViews::GetContentsView() { @@ -1287,7 +1287,7 @@ bool NativeWindowViews::ShouldDescendIntoChildForEventHandling( // And the events on border for dragging resizable frameless window. if (!has_frame() && CanResize()) { FramelessView* frame = - static_cast(window_->non_client_view()->frame_view()); + static_cast(widget()->non_client_view()->frame_view()); return frame->ResizingBorderHitTest(location) == HTNOWHERE; } diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 120da55df4..6e4525b7f3 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -138,7 +138,7 @@ class NativeWindowViews : public NativeWindow, void SetIcon(const gfx::ImageSkia& icon); #endif - views::Widget* widget() const { return window_.get(); } + views::Widget* widget() const { return widget_.get(); } views::View* content_view() const { return content_view_; } SkRegion* draggable_region() const { return draggable_region_.get(); } @@ -210,7 +210,7 @@ class NativeWindowViews : public NativeWindow, // Returns the restore state for the window. ui::WindowShowState GetRestoredState(); - std::unique_ptr window_; + std::unique_ptr widget_; views::View* content_view_; // Weak ref. views::View* focused_view_; // The view should be focused by default.