Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(929)

Unified Diff: views/controls/menu/native_menu_wayland.cc

Issue 7464027: Wayland support for views. views_desktop on Wayland. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated files to latest and fixed changes for dependent CLs Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: views/controls/menu/native_menu_wayland.cc
diff --git a/views/controls/menu/native_menu_wayland.cc b/views/controls/menu/native_menu_wayland.cc
new file mode 100644
index 0000000000000000000000000000000000000000..084b296e20e417f84a4e2b5df5e67e9a57af14e0
--- /dev/null
+++ b/views/controls/menu/native_menu_wayland.cc
@@ -0,0 +1,165 @@
+// Copyright (c) 2011 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.
+
+#include "views/controls/menu/native_menu_wayland.h"
+
+#include "base/logging.h"
+#include "base/utf_string_conversions.h"
+#include "ui/gfx/canvas_skia.h"
+#include "ui/gfx/skia_util.h"
+#include "views/controls/menu/menu_2.h"
+#include "views/controls/menu/submenu_view.h"
+
+namespace views {
+
+NativeMenuWayland::NativeMenuWayland(Menu2* menu)
+ : model_(menu->model()),
+ ALLOW_THIS_IN_INITIALIZER_LIST(root_(new MenuItemView(this))) {
+}
+
+NativeMenuWayland::~NativeMenuWayland() {
+}
+
+// MenuWrapper implementation:
+void NativeMenuWayland::RunMenuAt(const gfx::Point& point, int alignment) {
+ UpdateStates();
+ root_->RunMenuAt(NULL, NULL, gfx::Rect(point, gfx::Size()),
+ alignment == Menu2::ALIGN_TOPLEFT ? MenuItemView::TOPLEFT :
+ MenuItemView::TOPRIGHT, true);
+}
+
+void NativeMenuWayland::CancelMenu() {
+ NOTIMPLEMENTED();
+}
+
+void NativeMenuWayland::Rebuild() {
+ if (SubmenuView* submenu = root_->GetSubmenu()) {
+ submenu->RemoveAllChildViews(true);
+ }
+ AddMenuItemsFromModel(root_.get(), model_);
+}
+
+void NativeMenuWayland::UpdateStates() {
+ SubmenuView* submenu = root_->CreateSubmenu();
+ UpdateMenuFromModel(submenu, model_);
+}
+
+gfx::NativeMenu NativeMenuWayland::GetNativeMenu() const {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
+MenuWrapper::MenuAction NativeMenuWayland::GetMenuAction() const {
+ NOTIMPLEMENTED();
+ return MENU_ACTION_NONE;
+}
+
+void NativeMenuWayland::AddMenuListener(MenuListener* listener) {
+ NOTIMPLEMENTED();
+}
+
+void NativeMenuWayland::RemoveMenuListener(MenuListener* listener) {
+ NOTIMPLEMENTED();
+}
+
+void NativeMenuWayland::SetMinimumWidth(int width) {
+ NOTIMPLEMENTED();
+}
+
+// MenuDelegate implementation
+
+bool NativeMenuWayland::IsItemChecked(int cmd) const {
+ int index;
+ ui::MenuModel* model = model_;
+ if (!ui::MenuModel::GetModelAndIndexForCommandId(cmd, &model, &index))
+ return false;
+ return model->IsItemCheckedAt(index);
+}
+
+bool NativeMenuWayland::IsCommandEnabled(int cmd) const {
+ int index;
+ ui::MenuModel* model = model_;
+ if (!ui::MenuModel::GetModelAndIndexForCommandId(cmd, &model, &index))
+ return false;
+ return model->IsEnabledAt(index);
+}
+
+void NativeMenuWayland::ExecuteCommand(int cmd) {
+ int index;
+ ui::MenuModel* model = model_;
+ if (!ui::MenuModel::GetModelAndIndexForCommandId(cmd, &model, &index))
+ return;
+ model->ActivatedAt(index);
+}
+
+bool NativeMenuWayland::GetAccelerator(int id,
+ views::Accelerator* accelerator) {
+ int index;
+ ui::MenuModel* model = model_;
+ if (!ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index))
+ return false;
+
+ ui::Accelerator menu_accelerator;
+ if (!model->GetAcceleratorAt(index, &menu_accelerator))
+ return false;
+
+ *accelerator = views::Accelerator(menu_accelerator.key_code(),
+ menu_accelerator.modifiers());
+ return true;
+}
+
+// private
+void NativeMenuWayland::AddMenuItemsFromModel(MenuItemView* parent,
+ ui::MenuModel* model) {
+ for (int i = 0; i < model->GetItemCount(); ++i) {
+ int index = i + model->GetFirstItemIndex(NULL);
+ MenuItemView* child = parent->AppendMenuItemFromModel(model, index,
+ model->GetCommandIdAt(index));
+
+ if (child && child->GetType() == MenuItemView::SUBMENU) {
+ AddMenuItemsFromModel(child, model->GetSubmenuModelAt(index));
+ }
+ }
+}
+
+void NativeMenuWayland::UpdateMenuFromModel(SubmenuView* menu,
+ ui::MenuModel* model) {
+ for (int i = 0, sep = 0; i < model->GetItemCount(); ++i) {
+ int index = i + model->GetFirstItemIndex(NULL);
+ if (model->GetTypeAt(index) == ui::MenuModel::TYPE_SEPARATOR) {
+ ++sep;
+ continue;
+ }
+
+ // The submenu excludes the separators when counting the menu-items
+ // in it. So exclude the number of separators to get the correct index.
+ MenuItemView* mitem = menu->GetMenuItemAt(index - sep);
+ mitem->SetVisible(model->IsVisibleAt(index));
+ mitem->SetEnabled(model->IsEnabledAt(index));
+ if (model->IsItemDynamicAt(index)) {
+ mitem->SetTitle(UTF16ToWide(model->GetLabelAt(index)));
+ }
+
+ SkBitmap icon;
+ if (model->GetIconAt(index, &icon)) {
+ // TODO(atwilson): Support removing the icon dynamically
+ // (http://crbug.com/66508).
+ mitem->SetIcon(icon);
+ }
+
+ if (model->GetTypeAt(index) == ui::MenuModel::TYPE_SUBMENU) {
+ DCHECK(mitem->HasSubmenu());
+ UpdateMenuFromModel(mitem->GetSubmenu(), model->GetSubmenuModelAt(index));
+ }
+ }
+}
+
+// MenuWrapper, public:
+
+// static
+MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) {
+ return new NativeMenuWayland(menu);
+}
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698