2014-07-02 14:14:52 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
#ifndef ATOM_BROWSER_NATIVE_WINDOW_VIEWS_H_
|
|
|
|
#define ATOM_BROWSER_NATIVE_WINDOW_VIEWS_H_
|
2014-07-02 14:14:52 +00:00
|
|
|
|
|
|
|
#include "atom/browser/native_window.h"
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-07-04 08:54:10 +00:00
|
|
|
#include "atom/browser/ui/accelerator_util.h"
|
2014-07-03 17:30:36 +00:00
|
|
|
#include "ui/views/widget/widget_delegate.h"
|
2014-07-08 04:55:33 +00:00
|
|
|
#include "ui/views/widget/widget_observer.h"
|
2014-07-03 17:30:36 +00:00
|
|
|
|
|
|
|
namespace views {
|
2014-07-07 15:02:46 +00:00
|
|
|
class UnhandledKeyboardEventHandler;
|
2014-07-03 17:30:36 +00:00
|
|
|
class Widget;
|
|
|
|
}
|
2014-07-02 14:14:52 +00:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2014-07-11 00:57:19 +00:00
|
|
|
class GlobalMenuBarX11;
|
2014-07-16 14:10:10 +00:00
|
|
|
class MenuBar;
|
2014-07-11 00:57:19 +00:00
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
class NativeWindowViews : public NativeWindow,
|
2014-07-08 04:55:33 +00:00
|
|
|
public views::WidgetDelegateView,
|
|
|
|
public views::WidgetObserver {
|
2014-07-02 14:14:52 +00:00
|
|
|
public:
|
2014-07-03 17:30:36 +00:00
|
|
|
explicit NativeWindowViews(content::WebContents* web_contents,
|
2014-07-02 14:14:52 +00:00
|
|
|
const mate::Dictionary& options);
|
2014-07-03 17:30:36 +00:00
|
|
|
virtual ~NativeWindowViews();
|
2014-07-02 14:14:52 +00:00
|
|
|
|
|
|
|
// NativeWindow:
|
|
|
|
virtual void Close() OVERRIDE;
|
|
|
|
virtual void CloseImmediately() OVERRIDE;
|
|
|
|
virtual void Move(const gfx::Rect& pos) OVERRIDE;
|
|
|
|
virtual void Focus(bool focus) OVERRIDE;
|
|
|
|
virtual bool IsFocused() OVERRIDE;
|
|
|
|
virtual void Show() OVERRIDE;
|
|
|
|
virtual void Hide() OVERRIDE;
|
|
|
|
virtual bool IsVisible() OVERRIDE;
|
|
|
|
virtual void Maximize() OVERRIDE;
|
|
|
|
virtual void Unmaximize() OVERRIDE;
|
2014-07-07 15:49:28 +00:00
|
|
|
virtual bool IsMaximized() OVERRIDE;
|
2014-07-02 14:14:52 +00:00
|
|
|
virtual void Minimize() OVERRIDE;
|
|
|
|
virtual void Restore() OVERRIDE;
|
2014-07-26 05:58:26 +00:00
|
|
|
virtual bool IsMinimized() OVERRIDE;
|
2014-07-02 14:14:52 +00:00
|
|
|
virtual void SetFullscreen(bool fullscreen) OVERRIDE;
|
|
|
|
virtual bool IsFullscreen() OVERRIDE;
|
|
|
|
virtual void SetSize(const gfx::Size& size) OVERRIDE;
|
|
|
|
virtual gfx::Size GetSize() OVERRIDE;
|
|
|
|
virtual void SetContentSize(const gfx::Size& size) OVERRIDE;
|
|
|
|
virtual gfx::Size GetContentSize() OVERRIDE;
|
|
|
|
virtual void SetMinimumSize(const gfx::Size& size) OVERRIDE;
|
|
|
|
virtual gfx::Size GetMinimumSize() OVERRIDE;
|
|
|
|
virtual void SetMaximumSize(const gfx::Size& size) OVERRIDE;
|
|
|
|
virtual gfx::Size GetMaximumSize() OVERRIDE;
|
|
|
|
virtual void SetResizable(bool resizable) OVERRIDE;
|
|
|
|
virtual bool IsResizable() OVERRIDE;
|
|
|
|
virtual void SetAlwaysOnTop(bool top) OVERRIDE;
|
|
|
|
virtual bool IsAlwaysOnTop() OVERRIDE;
|
|
|
|
virtual void Center() OVERRIDE;
|
|
|
|
virtual void SetPosition(const gfx::Point& position) OVERRIDE;
|
|
|
|
virtual gfx::Point GetPosition() OVERRIDE;
|
|
|
|
virtual void SetTitle(const std::string& title) OVERRIDE;
|
|
|
|
virtual std::string GetTitle() OVERRIDE;
|
|
|
|
virtual void FlashFrame(bool flash) OVERRIDE;
|
|
|
|
virtual void SetSkipTaskbar(bool skip) OVERRIDE;
|
|
|
|
virtual void SetKiosk(bool kiosk) OVERRIDE;
|
|
|
|
virtual bool IsKiosk() OVERRIDE;
|
2014-07-04 08:54:10 +00:00
|
|
|
virtual void SetMenu(ui::MenuModel* menu_model) OVERRIDE;
|
2014-07-02 14:14:52 +00:00
|
|
|
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
|
|
|
|
|
2014-07-21 14:03:58 +00:00
|
|
|
gfx::AcceleratedWidget GetAcceleratedWidget();
|
|
|
|
|
2014-07-07 07:35:16 +00:00
|
|
|
SkRegion* draggable_region() const { return draggable_region_.get(); }
|
2014-07-10 04:07:01 +00:00
|
|
|
views::Widget* widget() const { return window_.get(); }
|
2014-07-07 07:35:16 +00:00
|
|
|
|
2014-07-02 14:14:52 +00:00
|
|
|
private:
|
|
|
|
// NativeWindow:
|
|
|
|
virtual void UpdateDraggableRegions(
|
|
|
|
const std::vector<DraggableRegion>& regions) OVERRIDE;
|
|
|
|
|
2014-07-08 04:55:33 +00:00
|
|
|
// views::WidgetObserver:
|
|
|
|
virtual void OnWidgetActivationChanged(
|
|
|
|
views::Widget* widget, bool active) OVERRIDE;
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
// views::WidgetDelegate:
|
|
|
|
virtual void DeleteDelegate() OVERRIDE;
|
|
|
|
virtual views::View* GetInitiallyFocusedView() OVERRIDE;
|
|
|
|
virtual bool CanResize() const OVERRIDE;
|
|
|
|
virtual bool CanMaximize() const OVERRIDE;
|
|
|
|
virtual base::string16 GetWindowTitle() const OVERRIDE;
|
|
|
|
virtual bool ShouldHandleSystemCommands() const OVERRIDE;
|
|
|
|
virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE;
|
|
|
|
virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
|
|
|
|
virtual views::Widget* GetWidget() OVERRIDE;
|
|
|
|
virtual const views::Widget* GetWidget() const OVERRIDE;
|
|
|
|
virtual views::View* GetContentsView() OVERRIDE;
|
2014-07-07 07:35:16 +00:00
|
|
|
virtual bool ShouldDescendIntoChildForEventHandling(
|
|
|
|
gfx::NativeView child,
|
|
|
|
const gfx::Point& location) OVERRIDE;
|
2014-07-03 17:30:36 +00:00
|
|
|
virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
|
2014-07-04 04:32:03 +00:00
|
|
|
virtual views::NonClientFrameView* CreateNonClientFrameView(
|
|
|
|
views::Widget* widget) OVERRIDE;
|
2014-07-03 17:30:36 +00:00
|
|
|
|
2014-07-04 08:54:10 +00:00
|
|
|
// content::WebContentsDelegate:
|
2014-08-07 06:14:43 +00:00
|
|
|
virtual void HandleMouseDown() OVERRIDE;
|
2014-07-04 08:54:10 +00:00
|
|
|
virtual void HandleKeyboardEvent(
|
|
|
|
content::WebContents*,
|
|
|
|
const content::NativeWebKeyboardEvent& event) OVERRIDE;
|
|
|
|
|
|
|
|
// views::View:
|
|
|
|
virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
|
|
|
|
|
|
|
|
// Register accelerators supported by the menu model.
|
|
|
|
void RegisterAccelerators(ui::MenuModel* menu_model);
|
|
|
|
|
2014-07-16 14:10:10 +00:00
|
|
|
// Converts between client area and window area, since we include the menu bar
|
|
|
|
// in client area we need to substract/add menu bar's height in convertions.
|
|
|
|
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& content_bounds);
|
|
|
|
|
2014-08-07 05:47:58 +00:00
|
|
|
// Show/Hide the menu bar.
|
|
|
|
void SetMenuBarVisibility(bool visible);
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
scoped_ptr<views::Widget> window_;
|
2014-07-04 08:54:10 +00:00
|
|
|
views::View* web_view_; // Managed by inspectable_web_contents_.
|
|
|
|
|
2014-08-07 05:47:58 +00:00
|
|
|
scoped_ptr<MenuBar> menu_bar_;
|
|
|
|
bool menu_bar_autohide_;
|
|
|
|
bool menu_bar_show_;
|
2014-08-07 07:54:05 +00:00
|
|
|
bool menu_bar_alt_pressed_;
|
2014-08-07 05:47:58 +00:00
|
|
|
|
2014-07-11 00:57:19 +00:00
|
|
|
#if defined(USE_X11)
|
|
|
|
scoped_ptr<GlobalMenuBarX11> global_menu_bar_;
|
|
|
|
#endif
|
|
|
|
|
2014-07-07 15:02:46 +00:00
|
|
|
// Handles unhandled keyboard messages coming back from the renderer process.
|
|
|
|
scoped_ptr<views::UnhandledKeyboardEventHandler> keyboard_event_handler_;
|
|
|
|
|
2014-07-04 08:54:10 +00:00
|
|
|
// Map from accelerator to menu item's command id.
|
|
|
|
accelerator_util::AcceleratorTable accelerator_table_;
|
2014-07-03 17:30:36 +00:00
|
|
|
|
2014-07-21 12:58:15 +00:00
|
|
|
bool use_content_size_;
|
2014-07-03 17:30:36 +00:00
|
|
|
bool resizable_;
|
|
|
|
std::string title_;
|
|
|
|
gfx::Size minimum_size_;
|
|
|
|
gfx::Size maximum_size_;
|
2014-07-02 14:14:52 +00:00
|
|
|
|
2014-07-07 07:35:16 +00:00
|
|
|
scoped_ptr<SkRegion> draggable_region_;
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(NativeWindowViews);
|
2014-07-02 14:14:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
#endif // ATOM_BROWSER_NATIVE_WINDOW_VIEWS_H_
|