#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"
"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);
.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
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_;
virtual void UpdateStates() = 0;
#endif
-#if defined(OS_WIN) || defined(OS_LINUX)
- virtual void AttachToWindow(Window* window) = 0;
-#endif
-
DISALLOW_COPY_AND_ASSIGN(Menu);
};
*/
}
-void MenuGtk::AttachToWindow(Window* window) {
- // static_cast<NativeWindowGtk*>(window->window())->SetMenu(model_.get());
-}
-
// static
mate::Wrappable* Menu::Create() {
return new MenuGtk();
protected:
virtual void Popup(Window* window) OVERRIDE;
- virtual void AttachToWindow(Window* window) OVERRIDE;
private:
scoped_ptr<::MenuGtk> menu_gtk_;
void NativeWindow::SetDocumentEdited(bool edited) {
}
+void NativeWindow::SetMenu(ui::MenuModel* menu) {
+}
+
bool NativeWindow::HasModalDialog() {
return has_dialog_attached_;
}
#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"
class Dictionary;
}
+namespace ui {
+class MenuModel;
+}
+
namespace atom {
class AtomJavaScriptDialogManager;
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;
#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"
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_);
// 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;
return IsFullscreen();
}
+void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
+ // FIXME
+ RegisterAccelerators(menu_model);
+}
+
gfx::NativeWindow NativeWindowViews::GetNativeWindow() {
return window_->GetNativeWindow();
}
}
views::View* NativeWindowViews::GetInitiallyFocusedView() {
- return web_view_;
+ return inspectable_web_contents()->GetView()->GetWebView();
}
bool NativeWindowViews::CanResize() const {
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) {
#include <string>
#include <vector>
+#include "atom/browser/ui/accelerator_util.h"
#include "ui/views/widget/widget_delegate.h"
namespace views {
-class WebView;
class Widget;
}
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:
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_;
-Subproject commit b2e79c9803b61a9b90aa45af32686e8ef9d4c571
+Subproject commit c4426492f5d0321e4c824a0443e6a261fc985ac7