views: Make acceleratros work.
This commit is contained in:
parent
0a38f3321e
commit
3c892b8591
9 changed files with 78 additions and 18 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "atom/browser/api/atom_api_menu.h"
|
||||
|
||||
#include "atom/browser/api/atom_api_window.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/ui/accelerator_util.h"
|
||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||
#include "native_mate/constructor.h"
|
||||
|
@ -157,6 +157,10 @@ void Menu::MenuWillShow(ui::SimpleMenuModel* source) {
|
|||
"menuWillShow", -1);
|
||||
}
|
||||
|
||||
void Menu::AttachToWindow(Window* window) {
|
||||
window->window()->SetMenu(model_.get());
|
||||
}
|
||||
|
||||
void Menu::InsertItemAt(
|
||||
int index, int command_id, const base::string16& label) {
|
||||
model_->InsertItemAt(index, command_id, label);
|
||||
|
@ -246,9 +250,7 @@ void Menu::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("isItemCheckedAt", &Menu::IsItemCheckedAt)
|
||||
.SetMethod("isEnabledAt", &Menu::IsEnabledAt)
|
||||
.SetMethod("isVisibleAt", &Menu::IsVisibleAt)
|
||||
#if defined(OS_WIN) || defined(OS_LINUX)
|
||||
.SetMethod("_attachToWindow", &Menu::AttachToWindow)
|
||||
#endif
|
||||
#if defined(OS_WIN)
|
||||
.SetMethod("_updateStates", &Menu::UpdateStates)
|
||||
#endif
|
||||
|
|
|
@ -53,6 +53,7 @@ class Menu : public mate::Wrappable,
|
|||
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
|
||||
virtual void MenuWillShow(ui::SimpleMenuModel* source) OVERRIDE;
|
||||
|
||||
virtual void AttachToWindow(Window* window);
|
||||
virtual void Popup(Window* window) = 0;
|
||||
|
||||
scoped_ptr<ui::SimpleMenuModel> model_;
|
||||
|
@ -87,10 +88,6 @@ class Menu : public mate::Wrappable,
|
|||
virtual void UpdateStates() = 0;
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN) || defined(OS_LINUX)
|
||||
virtual void AttachToWindow(Window* window) = 0;
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Menu);
|
||||
};
|
||||
|
||||
|
|
|
@ -38,10 +38,6 @@ void MenuGtk::Popup(Window* window) {
|
|||
*/
|
||||
}
|
||||
|
||||
void MenuGtk::AttachToWindow(Window* window) {
|
||||
// static_cast<NativeWindowGtk*>(window->window())->SetMenu(model_.get());
|
||||
}
|
||||
|
||||
// static
|
||||
mate::Wrappable* Menu::Create() {
|
||||
return new MenuGtk();
|
||||
|
|
|
@ -19,7 +19,6 @@ class MenuGtk : public Menu,
|
|||
|
||||
protected:
|
||||
virtual void Popup(Window* window) OVERRIDE;
|
||||
virtual void AttachToWindow(Window* window) OVERRIDE;
|
||||
|
||||
private:
|
||||
scoped_ptr<::MenuGtk> menu_gtk_;
|
||||
|
|
|
@ -197,6 +197,9 @@ void NativeWindow::SetRepresentedFilename(const std::string& filename) {
|
|||
void NativeWindow::SetDocumentEdited(bool edited) {
|
||||
}
|
||||
|
||||
void NativeWindow::SetMenu(ui::MenuModel* menu) {
|
||||
}
|
||||
|
||||
bool NativeWindow::HasModalDialog() {
|
||||
return has_dialog_attached_;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "atom/browser/native_window_observer.h"
|
||||
#include "atom/browser/ui/accelerator_util.h"
|
||||
#include "content/public/browser/notification_registrar.h"
|
||||
#include "content/public/browser/notification_observer.h"
|
||||
#include "vendor/brightray/browser/default_web_contents_delegate.h"
|
||||
|
@ -44,6 +45,10 @@ namespace mate {
|
|||
class Dictionary;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
class MenuModel;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomJavaScriptDialogManager;
|
||||
|
@ -129,6 +134,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
|||
virtual bool IsKiosk() = 0;
|
||||
virtual void SetRepresentedFilename(const std::string& filename);
|
||||
virtual void SetDocumentEdited(bool edited);
|
||||
virtual void SetMenu(ui::MenuModel* menu);
|
||||
virtual bool HasModalDialog();
|
||||
virtual gfx::NativeWindow GetNativeWindow() = 0;
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "browser/inspectable_web_contents_view.h"
|
||||
#include "content/public/browser/native_web_keyboard_event.h"
|
||||
#include "content/public/browser/web_contents_view.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
@ -47,7 +49,7 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
|
|||
const mate::Dictionary& options)
|
||||
: NativeWindow(web_contents, options),
|
||||
window_(new views::Widget),
|
||||
web_view_(new views::WebView(web_contents->GetBrowserContext())),
|
||||
web_view_(inspectable_web_contents()->GetView()->GetView()),
|
||||
resizable_(true) {
|
||||
options.Get(switches::kResizable, &resizable_);
|
||||
options.Get(switches::kTitle, &title_);
|
||||
|
@ -63,7 +65,6 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
|
|||
// Add web view.
|
||||
SetLayoutManager(new views::FillLayout);
|
||||
set_background(views::Background::CreateStandardPanelBackground());
|
||||
web_view_->SetWebContents(web_contents);
|
||||
AddChildView(web_view_);
|
||||
|
||||
int width = 800, height = 600;
|
||||
|
@ -239,6 +240,11 @@ bool NativeWindowViews::IsKiosk() {
|
|||
return IsFullscreen();
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
|
||||
// FIXME
|
||||
RegisterAccelerators(menu_model);
|
||||
}
|
||||
|
||||
gfx::NativeWindow NativeWindowViews::GetNativeWindow() {
|
||||
return window_->GetNativeWindow();
|
||||
}
|
||||
|
@ -253,7 +259,7 @@ void NativeWindowViews::DeleteDelegate() {
|
|||
}
|
||||
|
||||
views::View* NativeWindowViews::GetInitiallyFocusedView() {
|
||||
return web_view_;
|
||||
return inspectable_web_contents()->GetView()->GetWebView();
|
||||
}
|
||||
|
||||
bool NativeWindowViews::CanResize() const {
|
||||
|
@ -306,6 +312,42 @@ views::NonClientFrameView* NativeWindowViews::CreateNonClientFrameView(
|
|||
return frame_view;
|
||||
}
|
||||
|
||||
void NativeWindowViews::HandleKeyboardEvent(
|
||||
content::WebContents*,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
if (event.type == blink::WebInputEvent::RawKeyDown) {
|
||||
ui::Accelerator accelerator(
|
||||
static_cast<ui::KeyboardCode>(event.windowsKeyCode),
|
||||
content::GetModifiersFromNativeWebKeyboardEvent(event));
|
||||
|
||||
if (GetFocusManager()->ProcessAccelerator(accelerator)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool NativeWindowViews::AcceleratorPressed(const ui::Accelerator& accelerator) {
|
||||
return accelerator_util::TriggerAcceleratorTableCommand(
|
||||
&accelerator_table_, accelerator);
|
||||
}
|
||||
|
||||
void NativeWindowViews::RegisterAccelerators(ui::MenuModel* menu_model) {
|
||||
// Clear previous accelerators.
|
||||
views::FocusManager* focus_manager = GetFocusManager();
|
||||
accelerator_table_.clear();
|
||||
focus_manager->UnregisterAccelerators(this);
|
||||
|
||||
// Register accelerators with focus manager.
|
||||
accelerator_util::GenerateAcceleratorTable(&accelerator_table_, menu_model);
|
||||
accelerator_util::AcceleratorTable::const_iterator iter;
|
||||
for (iter = accelerator_table_.begin();
|
||||
iter != accelerator_table_.end();
|
||||
++iter) {
|
||||
focus_manager->RegisterAccelerator(
|
||||
iter->first, ui::AcceleratorManager::kNormalPriority, this);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
|
||||
const mate::Dictionary& options) {
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/ui/accelerator_util.h"
|
||||
#include "ui/views/widget/widget_delegate.h"
|
||||
|
||||
namespace views {
|
||||
class WebView;
|
||||
class Widget;
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@ class NativeWindowViews : public NativeWindow,
|
|||
virtual void SetSkipTaskbar(bool skip) OVERRIDE;
|
||||
virtual void SetKiosk(bool kiosk) OVERRIDE;
|
||||
virtual bool IsKiosk() OVERRIDE;
|
||||
virtual void SetMenu(ui::MenuModel* menu_model) OVERRIDE;
|
||||
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
|
||||
|
||||
private:
|
||||
|
@ -85,8 +86,22 @@ class NativeWindowViews : public NativeWindow,
|
|||
virtual views::NonClientFrameView* CreateNonClientFrameView(
|
||||
views::Widget* widget) OVERRIDE;
|
||||
|
||||
// content::WebContentsDelegate:
|
||||
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);
|
||||
|
||||
scoped_ptr<views::Widget> window_;
|
||||
views::WebView* web_view_; // managed by window_.
|
||||
views::View* web_view_; // Managed by inspectable_web_contents_.
|
||||
|
||||
// Map from accelerator to menu item's command id.
|
||||
accelerator_util::AcceleratorTable accelerator_table_;
|
||||
|
||||
bool resizable_;
|
||||
std::string title_;
|
||||
|
|
2
vendor/brightray
vendored
2
vendor/brightray
vendored
|
@ -1 +1 @@
|
|||
Subproject commit b2e79c9803b61a9b90aa45af32686e8ef9d4c571
|
||||
Subproject commit c4426492f5d0321e4c824a0443e6a261fc985ac7
|
Loading…
Reference in a new issue