| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" | 5 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 10 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 return std::string(); | 55 return std::string(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void RenderViewContextMenuGtk::StoppedShowing() { | 58 void RenderViewContextMenuGtk::StoppedShowing() { |
| 59 if (source_tab_contents_->render_widget_host_view()) | 59 if (source_tab_contents_->render_widget_host_view()) |
| 60 source_tab_contents_->render_widget_host_view()->ShowingContextMenu(false); | 60 source_tab_contents_->render_widget_host_view()->ShowingContextMenu(false); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void RenderViewContextMenuGtk::AppendMenuItem(int id) { | 63 void RenderViewContextMenuGtk::AppendMenuItem(int id) { |
| 64 AppendItem(id, std::wstring(), MENU_NORMAL); | 64 AppendItem(id, string16(), MENU_NORMAL); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void RenderViewContextMenuGtk::AppendMenuItem(int id, | 67 void RenderViewContextMenuGtk::AppendMenuItem(int id, |
| 68 const std::wstring& label) { | 68 const string16& label) { |
| 69 AppendItem(id, label, MENU_NORMAL); | 69 AppendItem(id, label, MENU_NORMAL); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void RenderViewContextMenuGtk::AppendRadioMenuItem(int id, | 72 void RenderViewContextMenuGtk::AppendRadioMenuItem(int id, |
| 73 const std::wstring& label) { | 73 const string16& label) { |
| 74 AppendItem(id, label, MENU_RADIO); | 74 AppendItem(id, label, MENU_RADIO); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void RenderViewContextMenuGtk::AppendCheckboxMenuItem(int id, | 77 void RenderViewContextMenuGtk::AppendCheckboxMenuItem(int id, |
| 78 const std::wstring& label) { | 78 const string16& label) { |
| 79 AppendItem(id, label, MENU_CHECKBOX); | 79 AppendItem(id, label, MENU_CHECKBOX); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void RenderViewContextMenuGtk::AppendSeparator() { | 82 void RenderViewContextMenuGtk::AppendSeparator() { |
| 83 AppendItem(0, std::wstring(), MENU_SEPARATOR); | 83 AppendItem(0, string16(), MENU_SEPARATOR); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void RenderViewContextMenuGtk::StartSubMenu(int id, const std::wstring& label) { | 86 void RenderViewContextMenuGtk::StartSubMenu(int id, const string16& label) { |
| 87 AppendItem(id, label, MENU_NORMAL); | 87 AppendItem(id, label, MENU_NORMAL); |
| 88 making_submenu_ = true; | 88 making_submenu_ = true; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void RenderViewContextMenuGtk::FinishSubMenu() { | 91 void RenderViewContextMenuGtk::FinishSubMenu() { |
| 92 DoneMakingMenu(&submenu_); | 92 DoneMakingMenu(&submenu_); |
| 93 menu_[menu_.size() - 1].submenu = submenu_.data(); | 93 menu_[menu_.size() - 1].submenu = submenu_.data(); |
| 94 making_submenu_ = false; | 94 making_submenu_ = false; |
| 95 } | 95 } |
| 96 | 96 |
| 97 // When a URL is copied from a render view context menu (via "copy link | 97 // When a URL is copied from a render view context menu (via "copy link |
| 98 // location", for example), we additionally stick it in the X clipboard. This | 98 // location", for example), we additionally stick it in the X clipboard. This |
| 99 // matches other linux browsers. | 99 // matches other linux browsers. |
| 100 void RenderViewContextMenuGtk::DidWriteURLToClipboard( | 100 void RenderViewContextMenuGtk::DidWriteURLToClipboard( |
| 101 const std::string& url) { | 101 const std::string& url) { |
| 102 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); | 102 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); |
| 103 gtk_clipboard_set_text(x_clipboard, url.c_str(), url.length()); | 103 gtk_clipboard_set_text(x_clipboard, url.c_str(), url.length()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void RenderViewContextMenuGtk::AppendItem( | 106 void RenderViewContextMenuGtk::AppendItem( |
| 107 int id, const std::wstring& label, MenuItemType type) { | 107 int id, const string16& label, MenuItemType type) { |
| 108 MenuCreateMaterial menu_create_material = { | 108 MenuCreateMaterial menu_create_material = { |
| 109 type, id, 0, 0, NULL | 109 type, id, 0, 0, NULL |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 if (label.empty()) | 112 if (label.empty()) |
| 113 menu_create_material.label_id = id; | 113 menu_create_material.label_id = id; |
| 114 else | 114 else |
| 115 label_map_[id] = WideToUTF8(label); | 115 label_map_[id] = UTF16ToUTF8(label); |
| 116 | 116 |
| 117 std::vector<MenuCreateMaterial>* menu = | 117 std::vector<MenuCreateMaterial>* menu = |
| 118 making_submenu_ ? &submenu_ : &menu_; | 118 making_submenu_ ? &submenu_ : &menu_; |
| 119 menu->push_back(menu_create_material); | 119 menu->push_back(menu_create_material); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // static | 122 // static |
| 123 void RenderViewContextMenuGtk::DoneMakingMenu( | 123 void RenderViewContextMenuGtk::DoneMakingMenu( |
| 124 std::vector<MenuCreateMaterial>* menu) { | 124 std::vector<MenuCreateMaterial>* menu) { |
| 125 static MenuCreateMaterial end_menu_item = { | 125 static MenuCreateMaterial end_menu_item = { |
| 126 MENU_END, 0, 0, 0, NULL | 126 MENU_END, 0, 0, 0, NULL |
| 127 }; | 127 }; |
| 128 menu->push_back(end_menu_item); | 128 menu->push_back(end_menu_item); |
| 129 } | 129 } |
| OLD | NEW |