[Win] Remove the extra MenuWrapper class.
This commit is contained in:
parent
738a929f8c
commit
dde07f03ec
6 changed files with 36 additions and 107 deletions
1
atom.gyp
1
atom.gyp
|
@ -110,7 +110,6 @@
|
||||||
'browser/ui/nsalert_synchronous_sheet_mac.mm',
|
'browser/ui/nsalert_synchronous_sheet_mac.mm',
|
||||||
'browser/ui/win/menu_2.cc',
|
'browser/ui/win/menu_2.cc',
|
||||||
'browser/ui/win/menu_2.h',
|
'browser/ui/win/menu_2.h',
|
||||||
'browser/ui/win/menu_wrapper.h',
|
|
||||||
'browser/ui/win/native_menu_win.cc',
|
'browser/ui/win/native_menu_win.cc',
|
||||||
'browser/ui/win/native_menu_win.h',
|
'browser/ui/win/native_menu_win.h',
|
||||||
'browser/window_list.cc',
|
'browser/window_list.cc',
|
||||||
|
|
|
@ -13,9 +13,10 @@ using namespace views; // NOLINT
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
Menu2::Menu2(ui::MenuModel* model)
|
Menu2::Menu2(ui::MenuModel* model, bool as_window_menu)
|
||||||
: model_(model),
|
: model_(model),
|
||||||
wrapper_(MenuWrapper::CreateWrapper(model)) {
|
wrapper_(new NativeMenuWin(model, NULL)) {
|
||||||
|
wrapper_->set_create_as_window_menu(as_window_menu);
|
||||||
Rebuild();
|
Rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ void Menu2::UpdateStates() {
|
||||||
wrapper_->UpdateStates();
|
wrapper_->UpdateStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuWrapper::MenuAction Menu2::GetMenuAction() const {
|
NativeMenuWin::MenuAction Menu2::GetMenuAction() const {
|
||||||
return wrapper_->GetMenuAction();
|
return wrapper_->GetMenuAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "browser/ui/win/menu_wrapper.h"
|
#include "browser/ui/win/native_menu_win.h"
|
||||||
#include "ui/gfx/native_widget_types.h"
|
#include "ui/gfx/native_widget_types.h"
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
@ -41,7 +41,7 @@ class Menu2 {
|
||||||
// from the constructor. EG:
|
// from the constructor. EG:
|
||||||
// MyClass : menu_(this) {}
|
// MyClass : menu_(this) {}
|
||||||
// is likely to have problems.
|
// is likely to have problems.
|
||||||
explicit Menu2(ui::MenuModel* model);
|
explicit Menu2(ui::MenuModel* model, bool as_window_menu = false);
|
||||||
virtual ~Menu2();
|
virtual ~Menu2();
|
||||||
|
|
||||||
// Runs the menu at the specified point. This method blocks until done.
|
// Runs the menu at the specified point. This method blocks until done.
|
||||||
|
@ -67,7 +67,7 @@ class Menu2 {
|
||||||
// Get the result of the last call to RunMenuAt to determine whether an
|
// Get the result of the last call to RunMenuAt to determine whether an
|
||||||
// item was selected, the user navigated to a next or previous menu, or
|
// item was selected, the user navigated to a next or previous menu, or
|
||||||
// nothing.
|
// nothing.
|
||||||
MenuWrapper::MenuAction GetMenuAction() const;
|
NativeMenuWin::MenuAction GetMenuAction() const;
|
||||||
|
|
||||||
// Add a listener to receive a callback when the menu opens.
|
// Add a listener to receive a callback when the menu opens.
|
||||||
void AddMenuListener(views::MenuListener* listener);
|
void AddMenuListener(views::MenuListener* listener);
|
||||||
|
@ -85,7 +85,7 @@ class Menu2 {
|
||||||
ui::MenuModel* model_;
|
ui::MenuModel* model_;
|
||||||
|
|
||||||
// The object that actually implements the menu.
|
// The object that actually implements the menu.
|
||||||
scoped_ptr<MenuWrapper> wrapper_;
|
scoped_ptr<NativeMenuWin> wrapper_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Menu2);
|
DISALLOW_COPY_AND_ASSIGN(Menu2);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
|
||||||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
#ifndef BROWSER_UI_WIN_MENU_WRAPPER_H_
|
|
||||||
#define BROWSER_UI_WIN_MENU_WRAPPER_H_
|
|
||||||
|
|
||||||
#include "ui/gfx/native_widget_types.h"
|
|
||||||
|
|
||||||
namespace gfx {
|
|
||||||
class Point;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ui {
|
|
||||||
class MenuModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace views {
|
|
||||||
class MenuInsertionDelegateWin;
|
|
||||||
class MenuListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
// An interface that wraps an object that implements a menu.
|
|
||||||
class MenuWrapper {
|
|
||||||
public:
|
|
||||||
// All of the possible actions that can result from RunMenuAt.
|
|
||||||
enum MenuAction {
|
|
||||||
MENU_ACTION_NONE, // Menu cancelled, or never opened.
|
|
||||||
MENU_ACTION_SELECTED, // An item was selected.
|
|
||||||
MENU_ACTION_PREVIOUS, // User wants to navigate to the previous menu.
|
|
||||||
MENU_ACTION_NEXT, // User wants to navigate to the next menu.
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual ~MenuWrapper() {}
|
|
||||||
|
|
||||||
// Creates the appropriate instance of this wrapper for the current platform.
|
|
||||||
static MenuWrapper* CreateWrapper(ui::MenuModel* model);
|
|
||||||
|
|
||||||
// Runs the menu at the specified point. This blocks until done.
|
|
||||||
virtual void RunMenuAt(const gfx::Point& point, int alignment) = 0;
|
|
||||||
|
|
||||||
// Cancels the active menu.
|
|
||||||
virtual void CancelMenu() = 0;
|
|
||||||
|
|
||||||
// Called when the model supplying data to this menu has changed, and the menu
|
|
||||||
// must be rebuilt.
|
|
||||||
virtual void Rebuild(views::MenuInsertionDelegateWin* delegate) = 0;
|
|
||||||
|
|
||||||
// Called when the states of the items in the menu must be updated from the
|
|
||||||
// model.
|
|
||||||
virtual void UpdateStates() = 0;
|
|
||||||
|
|
||||||
// Retrieve a native menu handle.
|
|
||||||
virtual HMENU GetNativeMenu() const = 0;
|
|
||||||
|
|
||||||
// Get the result of the last call to RunMenuAt to determine whether an
|
|
||||||
// item was selected, the user navigated to a next or previous menu, or
|
|
||||||
// nothing.
|
|
||||||
virtual MenuAction GetMenuAction() const = 0;
|
|
||||||
|
|
||||||
// Add a listener to receive a callback when the menu opens.
|
|
||||||
virtual void AddMenuListener(views::MenuListener* listener) = 0;
|
|
||||||
|
|
||||||
// Remove a menu listener.
|
|
||||||
virtual void RemoveMenuListener(views::MenuListener* listener) = 0;
|
|
||||||
|
|
||||||
// Sets the minimum width of the menu.
|
|
||||||
virtual void SetMinimumWidth(int width) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace atom
|
|
||||||
|
|
||||||
#endif // BROWSER_UI_WIN_MENU_WRAPPER_H_
|
|
|
@ -156,7 +156,7 @@ class NativeMenuWin::MenuHostWindow {
|
||||||
|
|
||||||
// Only notify the model if it didn't already send out notification.
|
// Only notify the model if it didn't already send out notification.
|
||||||
// See comment in MenuMessageHook for details.
|
// See comment in MenuMessageHook for details.
|
||||||
if (root_menu->menu_action_ == MenuWrapper::MENU_ACTION_NONE)
|
if (root_menu->menu_action_ == MENU_ACTION_NONE)
|
||||||
model->ActivatedAt(position);
|
model->ActivatedAt(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -758,12 +758,4 @@ void NativeMenuWin::CreateHostWindow() {
|
||||||
host_window_.reset(new MenuHostWindow(this));
|
host_window_.reset(new MenuHostWindow(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// MenuWrapper, public:
|
|
||||||
|
|
||||||
// static
|
|
||||||
MenuWrapper* MenuWrapper::CreateWrapper(ui::MenuModel* model) {
|
|
||||||
return new NativeMenuWin(model, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -14,34 +14,47 @@
|
||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "base/observer_list.h"
|
#include "base/observer_list.h"
|
||||||
#include "base/string16.h"
|
#include "base/string16.h"
|
||||||
#include "browser/ui/win/menu_wrapper.h"
|
|
||||||
|
namespace gfx {
|
||||||
|
class Point;
|
||||||
|
}
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
class MenuModel;
|
class MenuModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace views {
|
||||||
|
class MenuInsertionDelegateWin;
|
||||||
|
class MenuListener;
|
||||||
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
// A Windows implementation of MenuWrapper.
|
class NativeMenuWin {
|
||||||
// TODO(beng): rename to MenuWin once the old class is dead.
|
|
||||||
class NativeMenuWin : public MenuWrapper {
|
|
||||||
public:
|
public:
|
||||||
|
// All of the possible actions that can result from RunMenuAt.
|
||||||
|
enum MenuAction {
|
||||||
|
MENU_ACTION_NONE, // Menu cancelled, or never opened.
|
||||||
|
MENU_ACTION_SELECTED, // An item was selected.
|
||||||
|
MENU_ACTION_PREVIOUS, // User wants to navigate to the previous menu.
|
||||||
|
MENU_ACTION_NEXT, // User wants to navigate to the next menu.
|
||||||
|
};
|
||||||
|
|
||||||
// Construct a NativeMenuWin, with a model and delegate. If |system_menu_for|
|
// Construct a NativeMenuWin, with a model and delegate. If |system_menu_for|
|
||||||
// is non-NULL, the NativeMenuWin wraps the system menu for that window.
|
// is non-NULL, the NativeMenuWin wraps the system menu for that window.
|
||||||
// The caller owns the model and the delegate.
|
// The caller owns the model and the delegate.
|
||||||
NativeMenuWin(ui::MenuModel* model, HWND system_menu_for);
|
NativeMenuWin(ui::MenuModel* model, HWND system_menu_for);
|
||||||
virtual ~NativeMenuWin();
|
virtual ~NativeMenuWin();
|
||||||
|
|
||||||
// Overridden from MenuWrapper:
|
void RunMenuAt(const gfx::Point& point, int alignment);
|
||||||
virtual void RunMenuAt(const gfx::Point& point, int alignment) OVERRIDE;
|
void CancelMenu() ;
|
||||||
virtual void CancelMenu() OVERRIDE;
|
void Rebuild(views::MenuInsertionDelegateWin* delegate) ;
|
||||||
virtual void Rebuild(views::MenuInsertionDelegateWin* delegate) OVERRIDE;
|
void UpdateStates() ;
|
||||||
virtual void UpdateStates() OVERRIDE;
|
HMENU GetNativeMenu() const ;
|
||||||
virtual HMENU GetNativeMenu() const OVERRIDE;
|
MenuAction GetMenuAction() const ;
|
||||||
virtual MenuAction GetMenuAction() const OVERRIDE;
|
void AddMenuListener(views::MenuListener* listener) ;
|
||||||
virtual void AddMenuListener(views::MenuListener* listener) OVERRIDE;
|
void RemoveMenuListener(views::MenuListener* listener) ;
|
||||||
virtual void RemoveMenuListener(views::MenuListener* listener) OVERRIDE;
|
void SetMinimumWidth(int width) ;
|
||||||
virtual void SetMinimumWidth(int width) OVERRIDE;
|
|
||||||
|
|
||||||
// Flag to create a window menu instead of popup menu.
|
// Flag to create a window menu instead of popup menu.
|
||||||
void set_create_as_window_menu(bool flag) { create_as_window_menu_ = flag; }
|
void set_create_as_window_menu(bool flag) { create_as_window_menu_ = flag; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue