From 58c04862365b421000f042b12e33047537f9c110 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 5 Aug 2015 12:32:22 +0800 Subject: [PATCH 1/5] Remove duplicate UpdateDraggableRegions --- atom/browser/native_window.cc | 28 ++++++++++++++++++++++ atom/browser/native_window.h | 15 ++++++++---- atom/browser/native_window_mac.h | 9 -------- atom/browser/native_window_mac.mm | 36 ++--------------------------- atom/browser/native_window_views.cc | 27 ++-------------------- atom/browser/native_window_views.h | 7 ------ 6 files changed, 43 insertions(+), 79 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index d3c40f928272..c9d68df640a5 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -68,6 +68,25 @@ const char* kWebRuntimeFeatures[] = { switches::kPageVisibility, }; +// Convert draggable regions in raw format to SkRegion format. Caller is +// responsible for deleting the returned SkRegion instance. +SkRegion* DraggableRegionsToSkRegion( + const std::vector& regions) { + SkRegion* sk_region = new SkRegion; + for (std::vector::const_iterator iter = regions.begin(); + iter != regions.end(); + ++iter) { + const DraggableRegion& region = *iter; + sk_region->op( + region.bounds.x(), + region.bounds.y(), + region.bounds.right(), + region.bounds.bottom(), + region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); + } + return sk_region; +} + } // namespace NativeWindow::NativeWindow( @@ -559,6 +578,15 @@ bool NativeWindow::OnMessageReceived(const IPC::Message& message) { return handled; } +void NativeWindow::UpdateDraggableRegions( + const std::vector& regions) { + // Draggable region is not supported for non-frameless window. + if (has_frame_) + return; + + draggable_region_.reset(DraggableRegionsToSkRegion(regions)); +} + void NativeWindow::ScheduleUnresponsiveEvent(int ms) { if (!window_unresposive_closure_.IsCancelled()) return; diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index b9c2486b791b..611ff82011c5 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -23,6 +23,8 @@ #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_skia.h" +class SkRegion; + namespace base { class CommandLine; } @@ -217,6 +219,7 @@ class NativeWindow : public content::WebContentsObserver, } bool has_frame() const { return has_frame_; } + SkRegion* draggable_region() const { return draggable_region_.get(); } void set_has_dialog_attached(bool has_dialog_attached) { has_dialog_attached_ = has_dialog_attached; @@ -226,10 +229,6 @@ class NativeWindow : public content::WebContentsObserver, NativeWindow(brightray::InspectableWebContents* inspectable_web_contents, const mate::Dictionary& options); - // Called when the window needs to update its draggable region. - virtual void UpdateDraggableRegions( - const std::vector& regions) = 0; - // brightray::InspectableWebContentsViewDelegate: void DevToolsFocused() override; void DevToolsOpened() override; @@ -257,6 +256,10 @@ class NativeWindow : public content::WebContentsObserver, ObserverList observers_; private: + // Called when the window needs to update its draggable region. + void UpdateDraggableRegions( + const std::vector& regions); + // Schedule a notification unresponsive event. void ScheduleUnresponsiveEvent(int ms); @@ -298,6 +301,10 @@ class NativeWindow : public content::WebContentsObserver, // The page this window is viewing. brightray::InspectableWebContents* inspectable_web_contents_; + // For custom drag, the whole window is non-draggable and the draggable region + // has to been explicitly provided. + scoped_ptr draggable_region_; // used in custom drag. + base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(NativeWindow); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 67f4389ff703..e54dc6ad87f6 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -11,13 +11,11 @@ #include #include "base/mac/scoped_nsobject.h" -#include "base/memory/scoped_ptr.h" #include "atom/browser/native_window.h" @class AtomNSWindow; @class AtomNSWindowDelegate; @class FullSizeContentView; -class SkRegion; namespace atom { @@ -88,9 +86,6 @@ class NativeWindowMac : public NativeWindow { void ClipWebView(); protected: - void UpdateDraggableRegions( - const std::vector& regions) override; - // NativeWindow: void HandleKeyboardEvent( content::WebContents*, @@ -117,10 +112,6 @@ class NativeWindowMac : public NativeWindow { // The presentation options before entering kiosk mode. NSApplicationPresentationOptions kiosk_options_; - // For custom drag, the whole window is non-draggable and the draggable region - // has to been explicitly provided. - scoped_ptr draggable_region_; // used in custom drag. - // Mouse location since the last mouse event, in screen coordinates. This is // used in custom drag to compute the window movement. NSPoint last_mouse_offset_; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 295c0ac5400a..8a0955b2903c 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -318,29 +318,6 @@ static const CGFloat kAtomWindowCornerRadius = 4.0; namespace atom { -namespace { - -// Convert draggable regions in raw format to SkRegion format. Caller is -// responsible for deleting the returned SkRegion instance. -SkRegion* DraggableRegionsToSkRegion( - const std::vector& regions) { - SkRegion* sk_region = new SkRegion; - for (std::vector::const_iterator iter = regions.begin(); - iter != regions.end(); - ++iter) { - const DraggableRegion& region = *iter; - sk_region->op( - region.bounds.x(), - region.bounds.y(), - region.bounds.right(), - region.bounds.bottom(), - region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); - } - return sk_region; -} - -} // namespace - NativeWindowMac::NativeWindowMac( brightray::InspectableWebContents* web_contents, const mate::Dictionary& options) @@ -747,7 +724,7 @@ bool NativeWindowMac::IsVisibleOnAllWorkspaces() { } bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const { - if (!draggable_region_) + if (!draggable_region()) return false; if (!web_contents()) return false; @@ -756,7 +733,7 @@ bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const { // |draggable_region_| is stored in local platform-indepdent coordiate system // while |point| is in local Cocoa coordinate system. Do the conversion // to match these two. - return draggable_region_->contains(point.x, webViewHeight - point.y); + return draggable_region()->contains(point.x, webViewHeight - point.y); } void NativeWindowMac::HandleMouseEvent(NSEvent* event) { @@ -776,15 +753,6 @@ void NativeWindowMac::HandleMouseEvent(NSEvent* event) { } } -void NativeWindowMac::UpdateDraggableRegions( - const std::vector& regions) { - // Draggable region is not supported for non-frameless window. - if (has_frame_) - return; - - draggable_region_.reset(DraggableRegionsToSkRegion(regions)); -} - void NativeWindowMac::HandleKeyboardEvent( content::WebContents*, const content::NativeWebKeyboardEvent& event) { diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 62cf51f4d84e..35aea41eb549 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -753,29 +753,6 @@ gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() { return GetNativeWindow()->GetHost()->GetAcceleratedWidget(); } -void NativeWindowViews::UpdateDraggableRegions( - const std::vector& regions) { - if (has_frame_) - return; - - SkRegion* draggable_region = new SkRegion; - - // By default, the whole window is non-draggable. We need to explicitly - // include those draggable regions. - for (std::vector::const_iterator iter = regions.begin(); - iter != regions.end(); ++iter) { - const DraggableRegion& region = *iter; - draggable_region->op( - region.bounds.x(), - region.bounds.y(), - region.bounds.right(), - region.bounds.bottom(), - region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); - } - - draggable_region_.reset(draggable_region); -} - void NativeWindowViews::OnWidgetActivationChanged( views::Widget* widget, bool active) { if (widget != window_.get()) @@ -858,8 +835,8 @@ bool NativeWindowViews::ShouldDescendIntoChildForEventHandling( gfx::NativeView child, const gfx::Point& location) { // App window should claim mouse events that fall within the draggable region. - if (draggable_region_ && - draggable_region_->contains(location.x(), location.y())) + if (draggable_region() && + draggable_region()->contains(location.x(), location.y())) return false; // And the events on border for dragging resizable frameless window. diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index fa7e13c1c335..dcf1f603a4f4 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -82,14 +82,9 @@ class NativeWindowViews : public NativeWindow, gfx::AcceleratedWidget GetAcceleratedWidget(); - SkRegion* draggable_region() const { return draggable_region_.get(); } views::Widget* widget() const { return window_.get(); } private: - // NativeWindow: - void UpdateDraggableRegions( - const std::vector& regions) override; - // views::WidgetObserver: void OnWidgetActivationChanged( views::Widget* widget, bool active) override; @@ -177,8 +172,6 @@ class NativeWindowViews : public NativeWindow, gfx::Size maximum_size_; gfx::Size widget_size_; - scoped_ptr draggable_region_; - DISALLOW_COPY_AND_ASSIGN(NativeWindowViews); }; From 438a5acc0f7eefd90b706fbf276a99dae5a43d26 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 5 Aug 2015 12:34:45 +0800 Subject: [PATCH 2/5] Use ranged for loop --- atom/browser/native_window.cc | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index c9d68df640a5..0461b7d74eb8 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -70,13 +70,10 @@ const char* kWebRuntimeFeatures[] = { // Convert draggable regions in raw format to SkRegion format. Caller is // responsible for deleting the returned SkRegion instance. -SkRegion* DraggableRegionsToSkRegion( +scoped_ptr DraggableRegionsToSkRegion( const std::vector& regions) { - SkRegion* sk_region = new SkRegion; - for (std::vector::const_iterator iter = regions.begin(); - iter != regions.end(); - ++iter) { - const DraggableRegion& region = *iter; + scoped_ptr sk_region(new SkRegion); + for (const DraggableRegion& region : regions) { sk_region->op( region.bounds.x(), region.bounds.y(), @@ -84,7 +81,7 @@ SkRegion* DraggableRegionsToSkRegion( region.bounds.bottom(), region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); } - return sk_region; + return sk_region.Pass(); } } // namespace @@ -583,8 +580,7 @@ void NativeWindow::UpdateDraggableRegions( // Draggable region is not supported for non-frameless window. if (has_frame_) return; - - draggable_region_.reset(DraggableRegionsToSkRegion(regions)); + draggable_region_ = DraggableRegionsToSkRegion(regions); } void NativeWindow::ScheduleUnresponsiveEvent(int ms) { From 58b1172025ad754939aeefe7af2f2fe4b3e225ea Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 5 Aug 2015 12:46:32 +0800 Subject: [PATCH 3/5] Avoid exposing data members to subclass --- atom/browser/native_window.cc | 6 +++++ atom/browser/native_window.h | 41 ++++++++++++++++------------- atom/browser/native_window_mac.mm | 18 ++++++------- atom/browser/native_window_views.cc | 34 +++++++++++------------- 4 files changed, 53 insertions(+), 46 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 0461b7d74eb8..96085846bca8 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -522,6 +522,12 @@ void NativeWindow::NotifyWindowLeaveHtmlFullScreen() { OnWindowLeaveHtmlFullScreen()); } +void NativeWindow::NotifyWindowExecuteWindowsCommand( + const std::string& command) { + FOR_EACH_OBSERVER(NativeWindowObserver, observers_, + OnExecuteWindowsCommand(command)); +} + void NativeWindow::DevToolsFocused() { FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsFocus()); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 611ff82011c5..8919d529df03 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -205,11 +205,11 @@ class NativeWindow : public content::WebContentsObserver, void NotifyWindowLeaveFullScreen(); void NotifyWindowEnterHtmlFullScreen(); void NotifyWindowLeaveHtmlFullScreen(); + void NotifyWindowExecuteWindowsCommand(const std::string& command); void AddObserver(NativeWindowObserver* obs) { observers_.AddObserver(obs); } - void RemoveObserver(NativeWindowObserver* obs) { observers_.RemoveObserver(obs); } @@ -219,7 +219,10 @@ class NativeWindow : public content::WebContentsObserver, } bool has_frame() const { return has_frame_; } + bool transparent() const { return transparent_; } 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) { has_dialog_attached_ = has_dialog_attached; @@ -240,21 +243,6 @@ class NativeWindow : public content::WebContentsObserver, void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) 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 observers_; - private: // Called when the window needs to update its draggable region. void UpdateDraggableRegions( @@ -271,6 +259,22 @@ class NativeWindow : public content::WebContentsObserver, const SkBitmap& bitmap, 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 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. bool is_closed_; @@ -301,9 +305,8 @@ class NativeWindow : public content::WebContentsObserver, // The page this window is viewing. brightray::InspectableWebContents* inspectable_web_contents_; - // For custom drag, the whole window is non-draggable and the draggable region - // has to been explicitly provided. - scoped_ptr draggable_region_; // used in custom drag. + // Observers of this window. + ObserverList observers_; base::WeakPtrFactory weak_factory_; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 8a0955b2903c..d9ac903590f2 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -340,7 +340,7 @@ NativeWindowMac::NativeWindowMac( NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask; - if (!useStandardWindow || transparent_ || !has_frame_) { + if (!useStandardWindow || transparent() || !has_frame()) { styleMask |= NSTexturedBackgroundWindowMask; } @@ -350,12 +350,12 @@ NativeWindowMac::NativeWindowMac( backing:NSBackingStoreBuffered defer:YES]); [window_ setShell:this]; - [window_ setEnableLargerThanScreen:enable_larger_than_screen_]; + [window_ setEnableLargerThanScreen:enable_larger_than_screen()]; window_delegate_.reset([[AtomNSWindowDelegate alloc] initWithShell:this]); [window_ setDelegate:window_delegate_]; - if (transparent_) { + if (transparent()) { // Make window has transparent background. [window_ setOpaque:NO]; [window_ setHasShadow:NO]; @@ -363,7 +363,7 @@ NativeWindowMac::NativeWindowMac( } // Remove non-transparent corners, see http://git.io/vfonD. - if (!has_frame_) + if (!has_frame()) [window_ setOpaque:NO]; // 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. bool use_content_size = false; options.Get(switches::kUseContentSize, &use_content_size); - if (!has_frame_ || !use_content_size) + if (!has_frame() || !use_content_size) SetSize(gfx::Size(width, height)); // Enable the NSView to accept first mouse event. @@ -509,7 +509,7 @@ gfx::Rect NativeWindowMac::GetBounds() { } void NativeWindowMac::SetContentSize(const gfx::Size& size) { - if (!has_frame_) { + if (!has_frame()) { SetSize(size); return; } @@ -527,7 +527,7 @@ void NativeWindowMac::SetContentSize(const gfx::Size& size) { } gfx::Size NativeWindowMac::GetContentSize() { - if (!has_frame_) + if (!has_frame()) return GetSize(); NSRect bounds = [[window_ contentView] bounds]; @@ -588,7 +588,7 @@ void NativeWindowMac::Center() { void NativeWindowMac::SetTitle(const std::string& title) { // We don't want the title to show in transparent window. - if (transparent_) + if (transparent()) return; [window_ setTitle:base::SysUTF8ToNSString(title)]; @@ -779,7 +779,7 @@ void NativeWindowMac::HandleKeyboardEvent( void NativeWindowMac::InstallView() { NSView* view = inspectable_web_contents()->GetView()->GetNativeView(); - if (has_frame_) { + if (has_frame()) { // Add layer with white background for the contents view. base::scoped_nsobject layer([[CALayer alloc] init]); [layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 35aea41eb549..cb28f2dd9871 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -232,7 +232,7 @@ NativeWindowViews::NativeWindowViews( options.Get(switches::kResizable, &resizable_); #endif - if (enable_larger_than_screen_) + if (enable_larger_than_screen()) // We need to set a default maximum window size here otherwise Windows // will not allow us to resize the window larger than scree. // Setting directly to INT_MAX somehow doesn't work, so we just devide @@ -252,9 +252,9 @@ NativeWindowViews::NativeWindowViews( params.bounds = bounds; params.delegate = this; 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; #if defined(USE_X11) @@ -312,24 +312,24 @@ NativeWindowViews::NativeWindowViews( set_background(views::Background::CreateStandardPanelBackground()); AddChildView(web_view_); - if (has_frame_ && + if (has_frame() && options.Get(switches::kUseContentSize, &use_content_size_) && use_content_size_) bounds = ContentBoundsToWindowBounds(bounds); #if defined(OS_WIN) - if (!has_frame_) { + if (!has_frame()) { // Set Window style so that we get a minimize and maximize animation when // frameless. DWORD frame_style = WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION; // We should not show a frame for transparent window. - if (transparent_) + if (transparent()) frame_style &= ~(WS_THICKFRAME | WS_CAPTION); ::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, frame_style); } - if (transparent_) { + if (transparent()) { // Transparent window on Windows has to have WS_EX_COMPOSITED style. LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE); 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 // 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_->FrameTypeChanged(); } // The given window is most likely not rectangular since it uses // 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); window_->UpdateWindowIcon(); @@ -469,7 +469,7 @@ gfx::Rect NativeWindowViews::GetBounds() { } void NativeWindowViews::SetContentSize(const gfx::Size& size) { - if (!has_frame_) { + if (!has_frame()) { NativeWindow::SetSize(size); return; } @@ -480,7 +480,7 @@ void NativeWindowViews::SetContentSize(const gfx::Size& size) { } gfx::Size NativeWindowViews::GetContentSize() { - if (!has_frame_) + if (!has_frame()) return GetSize(); gfx::Size content_size = @@ -628,7 +628,7 @@ void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) { #endif // Do not show menu bar in frameless window. - if (!has_frame_) + if (!has_frame()) return; if (!menu_bar_) { @@ -812,7 +812,7 @@ bool NativeWindowViews::ShouldHandleSystemCommands() const { } gfx::ImageSkia NativeWindowViews::GetWindowAppIcon() { - return icon_; + return icon(); } gfx::ImageSkia NativeWindowViews::GetWindowIcon() { @@ -840,7 +840,7 @@ bool NativeWindowViews::ShouldDescendIntoChildForEventHandling( return false; // And the events on border for dragging resizable frameless window. - if (!has_frame_ && CanResize()) { + if (!has_frame() && CanResize()) { FramelessView* frame = static_cast( window_->non_client_view()->frame_view()); return frame->ResizingBorderHitTest(location) == HTNOWHERE; @@ -860,7 +860,7 @@ views::NonClientFrameView* NativeWindowViews::CreateNonClientFrameView( frame_view->Init(this, widget); return frame_view; #else - if (has_frame_) { + if (has_frame()) { return new NativeFrameView(this, widget); } else { FramelessView* frame_view = new FramelessView; @@ -892,9 +892,7 @@ bool NativeWindowViews::ExecuteWindowsCommand(int command_id) { NotifyWindowMaximize(); } else { std::string command = AppCommandToString(command_id); - FOR_EACH_OBSERVER(NativeWindowObserver, - observers_, - OnExecuteWindowsCommand(command)); + NotifyWindowExecuteWindowsCommand(command); } return false; } From adbb909b39238254b55f12ab432de380adb1ae0c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 5 Aug 2015 13:16:03 +0800 Subject: [PATCH 4/5] Move ShouldUseGlobalMenuBar to x_window_utils --- atom/browser/native_window_views.cc | 39 ----------------------------- atom/browser/ui/x/x_window_utils.cc | 36 ++++++++++++++++++++++++++ atom/browser/ui/x/x_window_utils.h | 3 +++ 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index cb28f2dd9871..63867111040f 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -43,9 +43,6 @@ #include "base/nix/xdg_util.h" #include "base/strings/string_util.h" #include "chrome/browser/ui/libgtk2ui/unity_service.h" -#include "dbus/bus.h" -#include "dbus/object_proxy.h" -#include "dbus/message.h" #include "ui/base/x/x11_util.h" #include "ui/gfx/x/x11_types.h" #include "ui/views/window/native_frame_view.h" @@ -70,42 +67,6 @@ const int kMenuBarHeight = 20; const int kMenuBarHeight = 25; #endif -#if defined(USE_X11) -// Returns true if the bus name "com.canonical.AppMenu.Registrar" is available. -bool ShouldUseGlobalMenuBar() { - dbus::Bus::Options options; - scoped_refptr bus(new dbus::Bus(options)); - - dbus::ObjectProxy* object_proxy = - bus->GetObjectProxy(DBUS_SERVICE_DBUS, dbus::ObjectPath(DBUS_PATH_DBUS)); - dbus::MethodCall method_call(DBUS_INTERFACE_DBUS, "ListNames"); - scoped_ptr response(object_proxy->CallMethodAndBlock( - &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); - if (!response) { - bus->ShutdownAndBlock(); - return false; - } - - dbus::MessageReader reader(response.get()); - dbus::MessageReader array_reader(NULL); - if (!reader.PopArray(&array_reader)) { - bus->ShutdownAndBlock(); - return false; - } - while (array_reader.HasMoreData()) { - std::string name; - if (array_reader.PopString(&name) && - name == "com.canonical.AppMenu.Registrar") { - bus->ShutdownAndBlock(); - return true; - } - } - - bus->ShutdownAndBlock(); - return false; -} -#endif - bool IsAltKey(const content::NativeWebKeyboardEvent& event) { #if defined(USE_X11) // 164 and 165 represent VK_LALT and VK_RALT. diff --git a/atom/browser/ui/x/x_window_utils.cc b/atom/browser/ui/x/x_window_utils.cc index eaef5475b777..a15affb05f1b 100644 --- a/atom/browser/ui/x/x_window_utils.cc +++ b/atom/browser/ui/x/x_window_utils.cc @@ -7,6 +7,9 @@ #include #include "base/strings/string_util.h" +#include "dbus/bus.h" +#include "dbus/object_proxy.h" +#include "dbus/message.h" #include "ui/base/x/x11_util.h" namespace atom { @@ -46,4 +49,37 @@ void SetWindowType(::Window xwindow, const std::string& type) { reinterpret_cast(&window_type), 1); } +bool ShouldUseGlobalMenuBar() { + dbus::Bus::Options options; + scoped_refptr bus(new dbus::Bus(options)); + + dbus::ObjectProxy* object_proxy = + bus->GetObjectProxy(DBUS_SERVICE_DBUS, dbus::ObjectPath(DBUS_PATH_DBUS)); + dbus::MethodCall method_call(DBUS_INTERFACE_DBUS, "ListNames"); + scoped_ptr response(object_proxy->CallMethodAndBlock( + &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); + if (!response) { + bus->ShutdownAndBlock(); + return false; + } + + dbus::MessageReader reader(response.get()); + dbus::MessageReader array_reader(NULL); + if (!reader.PopArray(&array_reader)) { + bus->ShutdownAndBlock(); + return false; + } + while (array_reader.HasMoreData()) { + std::string name; + if (array_reader.PopString(&name) && + name == "com.canonical.AppMenu.Registrar") { + bus->ShutdownAndBlock(); + return true; + } + } + + bus->ShutdownAndBlock(); + return false; +} + } // namespace atom diff --git a/atom/browser/ui/x/x_window_utils.h b/atom/browser/ui/x/x_window_utils.h index ccf56d1eb9cf..16f3ddac6ccd 100644 --- a/atom/browser/ui/x/x_window_utils.h +++ b/atom/browser/ui/x/x_window_utils.h @@ -22,6 +22,9 @@ void SetWMSpecState(::Window xwindow, bool enabled, ::Atom state); // Sets the _NET_WM_WINDOW_TYPE of window. void SetWindowType(::Window xwindow, const std::string& type); +// Returns true if the bus name "com.canonical.AppMenu.Registrar" is available. +bool ShouldUseGlobalMenuBar(); + } // namespace atom #endif // ATOM_BROWSER_UI_X_X_WINDOW_UTILS_H_ From bbd6c927b1e3a146ce78787c5ea8fb6227466608 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 5 Aug 2015 13:18:41 +0800 Subject: [PATCH 5/5] Remove a few unused headers --- atom/browser/native_window_views.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 63867111040f..5f3472a7ffdb 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -20,7 +20,6 @@ #include "brightray/browser/inspectable_web_contents_view.h" #include "content/public/browser/native_web_keyboard_event.h" #include "native_mate/dictionary.h" -#include "ui/aura/window.h" #include "ui/aura/window_tree_host.h" #include "ui/base/hit_test.h" #include "ui/gfx/image/image.h" @@ -39,8 +38,6 @@ #include "atom/browser/ui/views/native_frame_view.h" #include "atom/browser/ui/x/window_state_watcher.h" #include "atom/browser/ui/x/x_window_utils.h" -#include "base/environment.h" -#include "base/nix/xdg_util.h" #include "base/strings/string_util.h" #include "chrome/browser/ui/libgtk2ui/unity_service.h" #include "ui/base/x/x11_util.h"