summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/bookmarks/bookmark_context_menu.cc36
-rw-r--r--chrome/browser/bookmarks/bookmark_editor.h44
-rw-r--r--chrome/browser/browser.vcproj4
-rw-r--r--chrome/browser/gtk/bookmark_editor_gtk.cc308
-rw-r--r--chrome/browser/gtk/bookmark_editor_gtk.h110
-rw-r--r--chrome/browser/views/bookmark_bubble_view.cc9
-rw-r--r--chrome/browser/views/bookmark_editor_view.cc39
-rw-r--r--chrome/browser/views/bookmark_editor_view.h36
-rw-r--r--chrome/chrome.gyp3
9 files changed, 516 insertions, 73 deletions
diff --git a/chrome/browser/bookmarks/bookmark_context_menu.cc b/chrome/browser/bookmarks/bookmark_context_menu.cc
index 57f3631..039cd83 100644
--- a/chrome/browser/bookmarks/bookmark_context_menu.cc
+++ b/chrome/browser/bookmarks/bookmark_context_menu.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/bookmarks/bookmark_context_menu.h"
#include "base/compiler_specific.h"
+#include "chrome/browser/bookmarks/bookmark_editor.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/browser.h"
@@ -21,7 +22,6 @@
// TODO(port): Port these files.
#if defined(OS_WIN)
#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/views/bookmark_editor_view.h"
#include "chrome/browser/views/bookmark_manager_view.h"
#include "chrome/views/window/window.h"
#endif
@@ -189,7 +189,7 @@ class EditFolderController : public InputWindowDialog::Delegate,
// Used when adding a new bookmark. If a new bookmark is created it is selected
// in the bookmark manager.
-class SelectOnCreationHandler : public BookmarkEditorView::Handler {
+class SelectOnCreationHandler : public BookmarkEditor::Handler {
public:
explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) {
}
@@ -336,17 +336,13 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
}
if (selection_[0]->is_url()) {
-#if defined(OS_WIN)
- BookmarkEditorView::Configuration editor_config;
+ BookmarkEditor::Configuration editor_config;
if (configuration_ == BOOKMARK_BAR)
- editor_config = BookmarkEditorView::SHOW_TREE;
+ editor_config = BookmarkEditor::SHOW_TREE;
else
- editor_config = BookmarkEditorView::NO_TREE;
- BookmarkEditorView::Show(wnd_, profile_, NULL, selection_[0],
- editor_config, NULL);
-#else
- NOTIMPLEMENTED() << "BookmarkEditorView unimplemented";
-#endif
+ editor_config = BookmarkEditor::NO_TREE;
+ BookmarkEditor::Show(wnd_, profile_, NULL, selection_[0],
+ editor_config, NULL);
} else {
EditFolderController::Show(profile_, wnd_, selection_[0], false,
false);
@@ -368,21 +364,21 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: {
UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Add", profile_);
-#if defined(OS_WIN)
- BookmarkEditorView::Configuration editor_config;
- BookmarkEditorView::Handler* handler = NULL;
+ BookmarkEditor::Configuration editor_config;
+ BookmarkEditor::Handler* handler = NULL;
if (configuration_ == BOOKMARK_BAR) {
- editor_config = BookmarkEditorView::SHOW_TREE;
+ editor_config = BookmarkEditor::SHOW_TREE;
} else {
- editor_config = BookmarkEditorView::NO_TREE;
+ editor_config = BookmarkEditor::NO_TREE;
+#if defined(OS_WIN)
// This is owned by the BookmarkEditorView.
handler = new SelectOnCreationHandler(profile_);
- }
- BookmarkEditorView::Show(wnd_, profile_, GetParentForNewNodes(), NULL,
- editor_config, handler);
#else
- NOTIMPLEMENTED() << "Adding new bookmark not implemented";
+ NOTIMPLEMENTED() << "Custom SelectOnCreationHandler not implemented";
#endif
+ }
+ BookmarkEditor::Show(wnd_, profile_, GetParentForNewNodes(), NULL,
+ editor_config, handler);
break;
}
diff --git a/chrome/browser/bookmarks/bookmark_editor.h b/chrome/browser/bookmarks/bookmark_editor.h
new file mode 100644
index 0000000..5e356e1
--- /dev/null
+++ b/chrome/browser/bookmarks/bookmark_editor.h
@@ -0,0 +1,44 @@
+// Copyright (c) 2009 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 CHROME_BROWSER_BOOKMARKS_BOOKMARK_EDITOR_H_
+#define CHROME_BROWSER_BOOKMARKS_BOOKMARK_EDITOR_H_
+
+#include "base/gfx/native_widget_types.h"
+
+class BookmarkNode;
+class Profile;
+
+// Small, cross platform interface that shows the correct platform specific
+// bookmark editor dialog.
+class BookmarkEditor {
+ public:
+ // Handler is notified when the BookmarkEditor creates a new bookmark.
+ // Handler is owned by the BookmarkEditor and deleted when it is deleted.
+ class Handler {
+ public:
+ virtual ~Handler() {}
+ virtual void NodeCreated(BookmarkNode* new_node) = 0;
+ };
+
+ // An enumeration of the possible configurations offered.
+ enum Configuration {
+ SHOW_TREE,
+ NO_TREE
+ };
+
+ // Shows the platform specific BookmarkEditor subclass editing |node|. If
+ // |node| is NULL a new entry is created initially parented to |parent|. If
+ // |show_tree| is false the tree is not shown. BookmarkEditor takes
+ // ownership of |handler| and deletes it when done. |handler| may be
+ // null. See description of Handler for details.
+ static void Show(gfx::NativeWindow parent_window,
+ Profile* profile,
+ BookmarkNode* parent,
+ BookmarkNode* node,
+ Configuration configuration,
+ Handler* handler);
+};
+
+#endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_EDITOR_H_
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index b41bf15..96114e4 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -590,6 +590,10 @@
>
</File>
<File
+ RelativePath=".\bookmarks\bookmark_editor.h"
+ >
+ </File>
+ <File
RelativePath=".\bookmarks\bookmark_folder_tree_model.cc"
>
</File>
diff --git a/chrome/browser/gtk/bookmark_editor_gtk.cc b/chrome/browser/gtk/bookmark_editor_gtk.cc
new file mode 100644
index 0000000..dae1b8f
--- /dev/null
+++ b/chrome/browser/gtk/bookmark_editor_gtk.cc
@@ -0,0 +1,308 @@
+// Copyright (c) 2009 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 "chrome/browser/gtk/bookmark_editor_gtk.h"
+
+#include <gtk/gtk.h>
+
+#include "base/basictypes.h"
+#include "base/gfx/gtk_util.h"
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "chrome/browser/history/history.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/net/url_fixer_upper.h"
+#include "chrome/common/l10n_util.h"
+#include "googleurl/src/gurl.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "grit/locale_settings.h"
+
+namespace {
+
+// Background color of text field when URL is invalid.
+const GdkColor kErrorColor = GDK_COLOR_RGB(0xFF, 0xBC, 0xBC);
+
+// Preferred width of the tree.
+static const int kTreeWidth = 300;
+
+} // namespace
+
+// static
+void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd,
+ Profile* profile,
+ BookmarkNode* parent,
+ BookmarkNode* node,
+ Configuration configuration,
+ Handler* handler) {
+ DCHECK(profile);
+ BookmarkEditorGtk* editor =
+ new BookmarkEditorGtk(parent_hwnd, profile, parent, node, configuration,
+ handler);
+ editor->Show();
+}
+
+BookmarkEditorGtk::BookmarkEditorGtk(
+ GtkWindow* window,
+ Profile* profile,
+ BookmarkNode* parent,
+ BookmarkNode* node,
+ BookmarkEditor::Configuration configuration,
+ BookmarkEditor::Handler* handler)
+ : profile_(profile),
+ dialog_(NULL),
+ parent_(parent),
+ node_(node),
+ running_menu_for_root_(false),
+ show_tree_(configuration == SHOW_TREE),
+ handler_(handler) {
+ DCHECK(profile);
+ Init(window);
+}
+
+BookmarkEditorGtk::~BookmarkEditorGtk() {
+ // The tree model is deleted before the view. Reset the model otherwise the
+ // tree will reference a deleted model.
+
+ // TODO(erg): Enable this when we have a |tree_view_|.
+ // if (tree_view_)
+ // tree_view_->SetModel(NULL);
+ bb_model_->RemoveObserver(this);
+}
+
+void BookmarkEditorGtk::Init(GtkWindow* parent_window) {
+ bb_model_ = profile_->GetBookmarkModel();
+ DCHECK(bb_model_);
+ bb_model_->AddObserver(this);
+
+ dialog_ = gtk_dialog_new_with_buttons(
+ l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_TITLE).c_str(),
+ parent_window,
+ GTK_DIALOG_MODAL,
+ NULL);
+
+ // TODO(erg): Add "New Folder" button here and insert at correct place; to
+ // the extreme left of the dialog.
+ close_button_ = gtk_dialog_add_button(GTK_DIALOG(dialog_),
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_REJECT);
+ ok_button_ = gtk_dialog_add_button(GTK_DIALOG(dialog_),
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
+ gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT);
+
+ // The GTK dialog content area layout (overview)
+ //
+ // +- GtkVBox |content_area| --------------------------------------+
+ // |+- GtkTable |table| ------------------------------------------+|
+ // ||+- GtkLabel ------+ +- GtkEntry |name_entry_| --------------+||
+ // ||| | | |||
+ // ||+-----------------+ +---------------------------------------+||
+ // ||+- GtkLabel ------+ +- GtkEntry |url_entry_| ---------------+||
+ // ||| | | |||
+ // ||+-----------------+ +---------------------------------------+||
+ // |+-------------------------------------------------------------+|
+ // +---------------------------------------------------------------+
+ GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox;
+ gtk_container_set_border_width(GTK_CONTAINER(content_area), 12);
+ GtkWidget* table = gtk_table_new(2, 2, FALSE);
+
+ GtkWidget* label = gtk_label_new(
+ l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NAME_LABEL).c_str());
+ gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(label),
+ 0, 1, 0, 1,
+ (GtkAttachOptions)(GTK_SHRINK),
+ (GtkAttachOptions)(GTK_SHRINK),
+ 12, 0);
+ name_entry_ = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(name_entry_),
+ node_ ? WideToUTF8(node_->GetTitle()).c_str() : "");
+ g_signal_connect(G_OBJECT(name_entry_), "changed",
+ G_CALLBACK(OnEntryChanged), this);
+ g_object_set(G_OBJECT(name_entry_), "activates-default", TRUE, NULL);
+ gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(name_entry_),
+ 1, 2, 0, 1,
+ (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions)(GTK_FILL),
+ 0, 0);
+
+ label = gtk_label_new(
+ l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_URL_LABEL).c_str());
+ gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(label),
+ 0, 1, 1, 2,
+ (GtkAttachOptions)(GTK_SHRINK),
+ (GtkAttachOptions)(GTK_SHRINK),
+ 12, 0);
+ url_entry_ = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(url_entry_),
+ node_ ? node_->GetURL().spec().c_str() : "");
+ g_signal_connect(G_OBJECT(url_entry_), "changed",
+ G_CALLBACK(OnEntryChanged), this);
+ g_object_set(G_OBJECT(url_entry_), "activates-default", TRUE, NULL);
+ gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(url_entry_),
+ 1, 2, 1, 2,
+ (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions)(GTK_FILL),
+ 0, 0);
+
+ gtk_box_pack_start(GTK_BOX(content_area), table, FALSE, FALSE, 0);
+
+ // TODO(erg): Port the windows bookmark tree model and enable this tree view.
+ //
+ // folder_tree_ = gtk_tree_view_new();
+ // gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(folder_tree_), TRUE);
+ // gtk_widget_set_size_request(folder_tree_, kTreeWidth, -1);
+ // gtk_widget_show(folder_tree_);
+ // gtk_box_pack_start(GTK_BOX(content_area), folder_tree_, FALSE, FALSE, 0);
+
+ g_signal_connect(dialog_, "response",
+ G_CALLBACK(OnResponse), this);
+ g_signal_connect(dialog_, "delete-event",
+ G_CALLBACK(OnWindowDeleteEvent), this);
+ g_signal_connect(dialog_, "destroy",
+ G_CALLBACK(OnWindowDestroy), this);
+}
+
+void BookmarkEditorGtk::Show() {
+ // Manually call our OnEntryChanged handler to set the initial state.
+ OnEntryChanged(NULL, this);
+
+ gtk_widget_show_all(dialog_);
+}
+
+void BookmarkEditorGtk::Close() {
+ // Under the model that we've inherited from Windows, dialogs can receive
+ // more than one Close() call inside the current message loop event.
+ if (dialog_) {
+ gtk_widget_destroy(dialog_);
+ dialog_ = NULL;
+ }
+}
+
+void BookmarkEditorGtk::BookmarkNodeMoved(BookmarkModel* model,
+ BookmarkNode* old_parent,
+ int old_index,
+ BookmarkNode* new_parent,
+ int new_index) {
+ Reset();
+}
+
+void BookmarkEditorGtk::BookmarkNodeAdded(BookmarkModel* model,
+ BookmarkNode* parent,
+ int index) {
+ Reset();
+}
+
+void BookmarkEditorGtk::BookmarkNodeRemoved(BookmarkModel* model,
+ BookmarkNode* parent,
+ int index,
+ BookmarkNode* node) {
+ if ((node_ && node_->HasAncestor(node)) ||
+ (parent_ && parent_->HasAncestor(node))) {
+ // The node, or its parent was removed. Close the dialog.
+ Close();
+ } else {
+ Reset();
+ }
+}
+
+void BookmarkEditorGtk::BookmarkNodeChildrenReordered(BookmarkModel* model,
+ BookmarkNode* node) {
+ Reset();
+}
+
+void BookmarkEditorGtk::Reset() {
+ // TODO(erg): The windows implementation tries to be smart. For now, just
+ // close the window.
+ Close();
+}
+
+GURL BookmarkEditorGtk::GetInputURL() const {
+ std::wstring input = URLFixerUpper::FixupURL(
+ UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(url_entry_))), L"");
+ return GURL(WideToUTF8(input));
+}
+
+std::wstring BookmarkEditorGtk::GetInputTitle() const {
+ return UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(name_entry_)));
+}
+
+void BookmarkEditorGtk::ApplyEdits() {
+ // TODO(erg): This is massively simplified because I haven't added a
+ // GtkTreeView to this class yet. Then, this will have to be a copy of
+ // BookmarkEditorView::ApplyEdits().
+
+ // We're going to apply edits to the bookmark bar model, which will call us
+ // back. Normally when a structural edit occurs we reset the tree model.
+ // We don't want to do that here, so we remove ourselves as an observer.
+ bb_model_->RemoveObserver(this);
+
+ GURL new_url(GetInputURL());
+ std::wstring new_title(GetInputTitle());
+
+ BookmarkNode* old_parent = node_ ? node_->GetParent() : NULL;
+ const int old_index = old_parent ? old_parent->IndexOfChild(node_) : -1;
+
+ if (!node_) {
+ BookmarkNode* node =
+ bb_model_->AddURL(parent_, parent_->GetChildCount(), new_title,
+ new_url);
+ if (handler_.get())
+ handler_->NodeCreated(node);
+ return;
+ }
+ // If we're not showing the tree we only need to modify the node.
+ if (old_index == -1) {
+ NOTREACHED();
+ return;
+ }
+ if (new_url != node_->GetURL()) {
+ bb_model_->AddURLWithCreationTime(old_parent, old_index, new_title,
+ new_url, node_->date_added());
+ bb_model_->Remove(old_parent, old_index + 1);
+ } else {
+ bb_model_->SetTitle(node_, new_title);
+ }
+}
+
+// static
+void BookmarkEditorGtk::OnResponse(GtkDialog* dialog, int response_id,
+ BookmarkEditorGtk* window) {
+ if (response_id == GTK_RESPONSE_ACCEPT) {
+ window->ApplyEdits();
+ }
+
+ window->Close();
+}
+
+// static
+gboolean BookmarkEditorGtk::OnWindowDeleteEvent(
+ GtkWidget* widget,
+ GdkEvent* event,
+ BookmarkEditorGtk* dialog) {
+ dialog->Close();
+
+ // Return true to prevent the gtk dialog from being destroyed. Close will
+ // destroy it for us and the default gtk_dialog_delete_event_handler() will
+ // force the destruction without us being able to stop it.
+ return TRUE;
+}
+
+// static
+void BookmarkEditorGtk::OnWindowDestroy(GtkWidget* widget,
+ BookmarkEditorGtk* dialog) {
+ MessageLoop::current()->DeleteSoon(FROM_HERE, dialog);
+}
+
+// static
+void BookmarkEditorGtk::OnEntryChanged(GtkEditable* entry,
+ BookmarkEditorGtk* dialog) {
+ const GURL url(dialog->GetInputURL());
+ if (!url.is_valid()) {
+ gtk_widget_modify_base(dialog->url_entry_, GTK_STATE_NORMAL, &kErrorColor);
+ gtk_widget_set_sensitive(GTK_WIDGET(dialog->ok_button_), false);
+ } else {
+ gtk_widget_modify_base(dialog->url_entry_, GTK_STATE_NORMAL, NULL);
+ gtk_widget_set_sensitive(GTK_WIDGET(dialog->ok_button_), true);
+ }
+}
diff --git a/chrome/browser/gtk/bookmark_editor_gtk.h b/chrome/browser/gtk/bookmark_editor_gtk.h
new file mode 100644
index 0000000..1dbdbe8
--- /dev/null
+++ b/chrome/browser/gtk/bookmark_editor_gtk.h
@@ -0,0 +1,110 @@
+// Copyright (c) 2009 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 CHROME_BROWSER_GTK_BOOKMARK_EDITOR_GTK_H_
+#define CHROME_BROWSER_GTK_BOOKMARK_EDITOR_GTK_H_
+
+#include <gtk/gtk.h>
+
+#include "chrome/browser/bookmarks/bookmark_editor.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
+
+// GTK version of the bookmark editor dialog.
+class BookmarkEditorGtk : public BookmarkEditor,
+ public BookmarkModelObserver {
+ public:
+ BookmarkEditorGtk(GtkWindow* window,
+ Profile* profile,
+ BookmarkNode* parent,
+ BookmarkNode* node,
+ BookmarkEditor::Configuration configuration,
+ BookmarkEditor::Handler* handler);
+
+ virtual ~BookmarkEditorGtk();
+
+ void Show();
+ void Close();
+
+ private:
+ void Init(GtkWindow* parent_window);
+
+ // BookmarkModel observer methods. Any structural change results in
+ // resetting the tree model.
+ virtual void Loaded(BookmarkModel* model) { }
+ virtual void BookmarkNodeMoved(BookmarkModel* model,
+ BookmarkNode* old_parent,
+ int old_index,
+ BookmarkNode* new_parent,
+ int new_index);
+ virtual void BookmarkNodeAdded(BookmarkModel* model,
+ BookmarkNode* parent,
+ int index);
+ virtual void BookmarkNodeRemoved(BookmarkModel* model,
+ BookmarkNode* parent,
+ int index,
+ BookmarkNode* node);
+ virtual void BookmarkNodeChanged(BookmarkModel* model,
+ BookmarkNode* node) {}
+ virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
+ BookmarkNode* node);
+ virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
+ BookmarkNode* node) {}
+
+ // Resets the model of the tree and updates the various buttons appropriately.
+ void Reset();
+
+ // Returns the current url the user has input.
+ GURL GetInputURL() const;
+
+ // Returns the title the user has input.
+ std::wstring GetInputTitle() const;
+
+ void ApplyEdits();
+
+ static void OnResponse(GtkDialog* dialog, int response_id,
+ BookmarkEditorGtk* window);
+
+ static gboolean OnWindowDeleteEvent(GtkWidget* widget,
+ GdkEvent* event,
+ BookmarkEditorGtk* dialog);
+
+ static void OnWindowDestroy(GtkWidget* widget, BookmarkEditorGtk* dialog);
+ static void OnEntryChanged(GtkEditable* entry, BookmarkEditorGtk* dialog);
+
+ // Profile the entry is from.
+ Profile* profile_;
+
+ // The dialog to display on screen.
+ GtkWidget* dialog_;
+ GtkWidget* name_entry_;
+ GtkWidget* url_entry_;
+ GtkWidget* close_button_;
+ GtkWidget* ok_button_;
+ GtkWidget* folder_tree_;
+
+ // TODO(erg): BookmarkEditorView has an EditorTreeModel object here; convert
+ // that into a GObject that implements the interface GtkTreeModel.
+
+ // Initial parent to select. Is only used if node_ is NULL.
+ BookmarkNode* parent_;
+
+ // Node being edited. Is NULL if creating a new node.
+ BookmarkNode* node_;
+
+ // Mode used to create nodes from.
+ BookmarkModel* bb_model_;
+
+ // If true, we're running the menu for the bookmark bar or other bookmarks
+ // nodes.
+ bool running_menu_for_root_;
+
+ // Is the tree shown?
+ bool show_tree_;
+
+ scoped_ptr<BookmarkEditor::Handler> handler_;
+
+ DISALLOW_COPY_AND_ASSIGN(BookmarkEditorGtk);
+};
+
+#endif // CHROME_BROWSER_GTK_BOOKMARK_EDITOR_GTK_H_
diff --git a/chrome/browser/views/bookmark_bubble_view.cc b/chrome/browser/views/bookmark_bubble_view.cc
index 632357f..9c38f12 100644
--- a/chrome/browser/views/bookmark_bubble_view.cc
+++ b/chrome/browser/views/bookmark_bubble_view.cc
@@ -5,11 +5,11 @@
#include "chrome/browser/views/bookmark_bubble_view.h"
#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/bookmarks/bookmark_editor.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
-#include "chrome/browser/views/bookmark_editor_view.h"
#include "chrome/browser/views/info_bubble.h"
#include "chrome/browser/views/standard_layout.h"
#include "chrome/common/gfx/chrome_canvas.h"
@@ -373,9 +373,10 @@ void BookmarkBubbleView::ShowEditor() {
// the delete and all that.
Close();
- if (node)
- BookmarkEditorView::Show(parent, profile_, NULL, node,
- BookmarkEditorView::SHOW_TREE, NULL);
+ if (node) {
+ BookmarkEditor::Show(parent, profile_, NULL, node,
+ BookmarkEditor::SHOW_TREE, NULL);
+ }
}
void BookmarkBubbleView::ApplyEdits() {
diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc
index eb00198..60d8179 100644
--- a/chrome/browser/views/bookmark_editor_view.cc
+++ b/chrome/browser/views/bookmark_editor_view.cc
@@ -42,11 +42,25 @@ static const int kTreeWidth = 300;
// ID for various children.
static const int kNewGroupButtonID = 1002;
-BookmarkEditorView::BookmarkEditorView(Profile* profile,
- BookmarkNode* parent,
- BookmarkNode* node,
- Configuration configuration,
- Handler* handler)
+// static
+void BookmarkEditor::Show(HWND parent_hwnd,
+ Profile* profile,
+ BookmarkNode* parent,
+ BookmarkNode* node,
+ Configuration configuration,
+ Handler* handler) {
+ DCHECK(profile);
+ BookmarkEditorView* editor =
+ new BookmarkEditorView(profile, parent, node, configuration, handler);
+ editor->Show(parent_hwnd);
+}
+
+BookmarkEditorView::BookmarkEditorView(
+ Profile* profile,
+ BookmarkNode* parent,
+ BookmarkNode* node,
+ BookmarkEditor::Configuration configuration,
+ BookmarkEditor::Handler* handler)
: profile_(profile),
tree_view_(NULL),
new_group_button_(NULL),
@@ -67,19 +81,6 @@ BookmarkEditorView::~BookmarkEditorView() {
bb_model_->RemoveObserver(this);
}
-// static
-void BookmarkEditorView::Show(HWND parent_hwnd,
- Profile* profile,
- BookmarkNode* parent,
- BookmarkNode* node,
- Configuration configuration,
- Handler* handler) {
- DCHECK(profile);
- BookmarkEditorView* editor =
- new BookmarkEditorView(profile, parent, node, configuration, handler);
- editor->Show(parent_hwnd);
-}
-
bool BookmarkEditorView::IsDialogButtonEnabled(
MessageBoxFlags::DialogButton button) const {
if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
@@ -489,7 +490,7 @@ void BookmarkEditorView::ApplyEdits(EditorNode* parent) {
BookmarkNode* old_parent = node_ ? node_->GetParent() : NULL;
const int old_index = old_parent ? old_parent->IndexOfChild(node_) : -1;
- if (!show_tree_ ) {
+ if (!show_tree_) {
if (!node_) {
BookmarkNode* node =
bb_model_->AddURL(parent_, parent_->GetChildCount(), new_title,
diff --git a/chrome/browser/views/bookmark_editor_view.h b/chrome/browser/views/bookmark_editor_view.h
index 6b472d2..8414544 100644
--- a/chrome/browser/views/bookmark_editor_view.h
+++ b/chrome/browser/views/bookmark_editor_view.h
@@ -7,6 +7,7 @@
#include <set>
+#include "chrome/browser/bookmarks/bookmark_editor.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/views/controls/button/button.h"
#include "chrome/views/controls/menu/menu.h"
@@ -32,7 +33,8 @@ class Profile;
//
// To use BookmarkEditorView invoke the static show method.
-class BookmarkEditorView : public views::View,
+class BookmarkEditorView : public BookmarkEditor,
+ public views::View,
public views::ButtonListener,
public views::TreeViewController,
public views::DialogDelegate,
@@ -51,40 +53,14 @@ class BookmarkEditorView : public views::View,
FRIEND_TEST(BookmarkEditorViewTest, ChangeURLNoTree);
FRIEND_TEST(BookmarkEditorViewTest, ChangeTitleNoTree);
public:
- // Handler is notified when the BookmarkEditorView creates a new bookmark.
- // Handler is owned by the BookmarkEditorView and deleted when it is deleted.
- class Handler {
- public:
- virtual ~Handler() {}
- virtual void NodeCreated(BookmarkNode* new_node) = 0;
- };
-
- // An enumeration of the possible configurations offered.
- enum Configuration {
- SHOW_TREE,
- NO_TREE
- };
-
BookmarkEditorView(Profile* profile,
BookmarkNode* parent,
BookmarkNode* node,
- Configuration configuration,
- Handler* handler);
+ BookmarkEditor::Configuration configuration,
+ BookmarkEditor::Handler* handler);
virtual ~BookmarkEditorView();
- // Shows the BookmarkEditorView editing |node|. If |node| is NULL a new entry
- // is created initially parented to |parent|. If |show_tree| is false the
- // tree is not shown. BookmarkEditorView takes ownership of |handler| and
- // deletes it when done. |handler| may be null. See description of Handler
- // for details.
- static void Show(HWND parent_window,
- Profile* profile,
- BookmarkNode* parent,
- BookmarkNode* node,
- Configuration configuration,
- Handler* handler);
-
// DialogDelegate methods:
virtual bool IsDialogButtonEnabled(
MessageBoxFlags::DialogButton button) const;
@@ -280,7 +256,7 @@ class BookmarkEditorView : public views::View,
// Is the tree shown?
bool show_tree_;
- scoped_ptr<Handler> handler_;
+ scoped_ptr<BookmarkEditor::Handler> handler_;
DISALLOW_COPY_AND_ASSIGN(BookmarkEditorView);
};
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 617af10..88ba594 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -458,6 +458,7 @@
'browser/bookmarks/bookmark_drag_data.h',
'browser/bookmarks/bookmark_drop_info.cc',
'browser/bookmarks/bookmark_drop_info.h',
+ 'browser/bookmarks/bookmark_editor.h',
'browser/bookmarks/bookmark_folder_tree_model.cc',
'browser/bookmarks/bookmark_folder_tree_model.h',
'browser/bookmarks/bookmark_html_writer.cc',
@@ -724,6 +725,8 @@
'browser/gtk/back_forward_menu_model_gtk.h',
'browser/gtk/bookmark_bar_gtk.cc',
'browser/gtk/bookmark_bar_gtk.h',
+ 'browser/gtk/bookmark_editor_gtk.cc',
+ 'browser/gtk/bookmark_editor_gtk.h',
'browser/gtk/browser_toolbar_gtk.cc',
'browser/gtk/browser_toolbar_gtk.h',
'browser/gtk/browser_window_factory_gtk.cc',