2013-07-05 10:33:37 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-07-05 10:33:37 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_NATIVE_WINDOW_WIN_H_
|
|
|
|
#define ATOM_BROWSER_NATIVE_WINDOW_WIN_H_
|
|
|
|
|
2014-03-16 01:13:06 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2013-07-05 10:33:37 +00:00
|
|
|
#include "base/memory/scoped_ptr.h"
|
2014-01-15 13:28:00 +00:00
|
|
|
#include "base/strings/string16.h"
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/native_window.h"
|
|
|
|
#include "atom/browser/ui/accelerator_util.h"
|
2013-07-05 10:33:37 +00:00
|
|
|
#include "ui/gfx/size.h"
|
2014-05-24 04:57:14 +00:00
|
|
|
#include "ui/views/focus/widget_focus_manager.h"
|
2013-07-08 02:48:59 +00:00
|
|
|
#include "ui/views/widget/widget_delegate.h"
|
2014-06-11 01:13:55 +00:00
|
|
|
#include "vendor/brightray/browser/win/inspectable_web_contents_view_win.h"
|
2013-07-05 10:33:37 +00:00
|
|
|
|
2013-10-02 13:24:21 +00:00
|
|
|
namespace ui {
|
|
|
|
class MenuModel;
|
|
|
|
}
|
|
|
|
|
2013-07-05 10:33:37 +00:00
|
|
|
namespace views {
|
|
|
|
class Widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2013-10-02 13:24:21 +00:00
|
|
|
class Menu2;
|
|
|
|
|
2013-07-08 02:48:59 +00:00
|
|
|
class NativeWindowWin : public NativeWindow,
|
2014-05-24 04:57:14 +00:00
|
|
|
public views::WidgetFocusChangeListener,
|
2013-10-04 00:52:45 +00:00
|
|
|
public views::WidgetDelegateView {
|
2013-07-05 10:33:37 +00:00
|
|
|
public:
|
|
|
|
explicit NativeWindowWin(content::WebContents* web_contents,
|
2014-06-23 13:51:42 +00:00
|
|
|
const mate::Dictionary& options);
|
2013-07-05 10:33:37 +00:00
|
|
|
virtual ~NativeWindowWin();
|
|
|
|
|
|
|
|
// NativeWindow implementation.
|
|
|
|
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;
|
2013-10-03 00:27:59 +00:00
|
|
|
virtual bool IsVisible() OVERRIDE;
|
2013-07-05 10:33:37 +00:00
|
|
|
virtual void Maximize() OVERRIDE;
|
|
|
|
virtual void Unmaximize() OVERRIDE;
|
|
|
|
virtual void Minimize() OVERRIDE;
|
|
|
|
virtual void Restore() OVERRIDE;
|
|
|
|
virtual void SetFullscreen(bool fullscreen) OVERRIDE;
|
|
|
|
virtual bool IsFullscreen() OVERRIDE;
|
|
|
|
virtual void SetSize(const gfx::Size& size) OVERRIDE;
|
|
|
|
virtual gfx::Size GetSize() OVERRIDE;
|
2014-05-15 08:05:35 +00:00
|
|
|
virtual void SetContentSize(const gfx::Size& size) OVERRIDE;
|
2014-05-15 07:30:04 +00:00
|
|
|
virtual gfx::Size GetContentSize() OVERRIDE;
|
2013-07-05 10:33:37 +00:00
|
|
|
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;
|
2014-06-16 02:29:51 +00:00
|
|
|
virtual void SetSkipTaskbar(bool skip) OVERRIDE;
|
2013-07-05 10:33:37 +00:00
|
|
|
virtual void SetKiosk(bool kiosk) OVERRIDE;
|
|
|
|
virtual bool IsKiosk() OVERRIDE;
|
|
|
|
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
|
|
|
|
|
2013-10-03 15:34:42 +00:00
|
|
|
void OnMenuCommand(int position, HMENU menu);
|
|
|
|
|
2013-10-02 13:24:21 +00:00
|
|
|
// Set the native window menu.
|
|
|
|
void SetMenu(ui::MenuModel* menu_model);
|
|
|
|
|
2014-06-11 01:13:55 +00:00
|
|
|
brightray::InspectableWebContentsViewWin* inspectable_web_contents_view()
|
|
|
|
const {
|
|
|
|
return static_cast<brightray::InspectableWebContentsViewWin*>(
|
|
|
|
inspectable_web_contents()->GetView());
|
|
|
|
}
|
|
|
|
|
2013-10-03 15:34:42 +00:00
|
|
|
views::Widget* window() const { return window_.get(); }
|
2014-05-26 03:34:36 +00:00
|
|
|
atom::Menu2* menu() const { return menu_.get(); }
|
2013-09-09 04:12:17 +00:00
|
|
|
SkRegion* draggable_region() { return draggable_region_.get(); }
|
|
|
|
|
2013-07-05 10:33:37 +00:00
|
|
|
protected:
|
2013-09-05 12:06:54 +00:00
|
|
|
virtual void UpdateDraggableRegions(
|
|
|
|
const std::vector<DraggableRegion>& regions) OVERRIDE;
|
|
|
|
|
2013-07-08 02:48:59 +00:00
|
|
|
// Overridden from content::WebContentsDelegate:
|
2013-07-05 10:33:37 +00:00
|
|
|
virtual void HandleKeyboardEvent(
|
|
|
|
content::WebContents*,
|
|
|
|
const content::NativeWebKeyboardEvent&) OVERRIDE;
|
|
|
|
|
2013-10-04 00:52:45 +00:00
|
|
|
// Overridden from views::View:
|
|
|
|
virtual void Layout() OVERRIDE;
|
2013-12-17 10:34:45 +00:00
|
|
|
virtual void ViewHierarchyChanged(
|
|
|
|
const ViewHierarchyChangedDetails& details) OVERRIDE;
|
2013-10-04 15:36:31 +00:00
|
|
|
virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
|
2013-10-04 00:52:45 +00:00
|
|
|
|
2013-07-08 02:48:59 +00:00
|
|
|
// Overridden from views::WidgetDelegate:
|
2013-10-04 00:52:45 +00:00
|
|
|
virtual void DeleteDelegate() OVERRIDE;
|
2013-10-04 15:38:37 +00:00
|
|
|
virtual views::View* GetInitiallyFocusedView() OVERRIDE;
|
2013-07-08 02:48:59 +00:00
|
|
|
virtual bool CanResize() const OVERRIDE;
|
|
|
|
virtual bool CanMaximize() const OVERRIDE;
|
2014-06-28 14:33:00 +00:00
|
|
|
virtual base::string16 GetWindowTitle() const OVERRIDE;
|
2013-07-08 02:48:59 +00:00
|
|
|
virtual bool ShouldHandleSystemCommands() const OVERRIDE;
|
2013-11-11 11:23:35 +00:00
|
|
|
virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE;
|
|
|
|
virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
|
2013-07-08 02:48:59 +00:00
|
|
|
virtual views::Widget* GetWidget() OVERRIDE;
|
|
|
|
virtual const views::Widget* GetWidget() const OVERRIDE;
|
2013-07-08 09:00:42 +00:00
|
|
|
virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
|
2013-07-08 09:24:54 +00:00
|
|
|
virtual views::NonClientFrameView* CreateNonClientFrameView(
|
|
|
|
views::Widget* widget) OVERRIDE;
|
2013-07-08 02:48:59 +00:00
|
|
|
|
2014-05-24 04:57:14 +00:00
|
|
|
// Overridden from views::WidgetFocusChangeListener:
|
|
|
|
virtual void OnNativeFocusChange(gfx::NativeView focused_before,
|
|
|
|
gfx::NativeView focused_now) OVERRIDE;
|
|
|
|
|
2013-07-05 10:33:37 +00:00
|
|
|
private:
|
2013-10-04 15:36:31 +00:00
|
|
|
typedef struct { int position; ui::MenuModel* model; } MenuItem;
|
|
|
|
typedef std::map<ui::Accelerator, MenuItem> AcceleratorTable;
|
|
|
|
|
2014-05-18 13:27:23 +00:00
|
|
|
void ClientAreaSizeToWindowSize(gfx::Size* size);
|
|
|
|
|
2013-09-09 06:30:07 +00:00
|
|
|
void OnViewWasResized();
|
|
|
|
|
2013-10-04 15:36:31 +00:00
|
|
|
// Register accelerators supported by the menu model.
|
|
|
|
void RegisterAccelerators();
|
|
|
|
|
2013-07-05 10:33:37 +00:00
|
|
|
scoped_ptr<views::Widget> window_;
|
2014-06-11 01:13:55 +00:00
|
|
|
views::View* web_view_; // managed by window_.
|
2013-07-05 10:33:37 +00:00
|
|
|
|
2013-10-02 13:24:21 +00:00
|
|
|
// The window menu.
|
|
|
|
scoped_ptr<atom::Menu2> menu_;
|
|
|
|
|
2013-10-04 15:36:31 +00:00
|
|
|
// Map from accelerator to menu item's command id.
|
2014-03-15 08:36:29 +00:00
|
|
|
accelerator_util::AcceleratorTable accelerator_table_;
|
2013-10-04 15:36:31 +00:00
|
|
|
|
2013-09-09 04:12:17 +00:00
|
|
|
scoped_ptr<SkRegion> draggable_region_;
|
|
|
|
|
2014-05-18 13:27:23 +00:00
|
|
|
bool use_content_size_;
|
|
|
|
|
2013-07-05 10:33:37 +00:00
|
|
|
bool resizable_;
|
2014-06-28 14:33:00 +00:00
|
|
|
base::string16 title_;
|
2013-07-05 10:33:37 +00:00
|
|
|
gfx::Size minimum_size_;
|
|
|
|
gfx::Size maximum_size_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(NativeWindowWin);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_NATIVE_WINDOW_WIN_H_
|