diff options
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 13 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 16 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.h | 3 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/tab_contents_container_gtk.cc | 3 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.cc | 22 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.h | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/view_id_util.cc | 72 | ||||
-rw-r--r-- | chrome/browser/gtk/view_id_util.h | 27 | ||||
-rw-r--r-- | chrome/browser/gtk/view_id_util_unittest.cc | 43 |
11 files changed, 207 insertions, 5 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index 852aef1..36456c9 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -25,6 +25,7 @@ #include "chrome/browser/gtk/gtk_dnd_util.h" #include "chrome/browser/gtk/gtk_theme_provider.h" #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" +#include "chrome/browser/gtk/view_id_util.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -200,14 +201,16 @@ void BookmarkBarGtk::Init(Profile* profile) { gtk_widget_set_size_request(event_box_.get(), -1, 0); slide_animation_.reset(new SlideAnimation(this)); + + ViewIDUtil::SetID(widget(), VIEW_ID_BOOKMARK_BAR); } void BookmarkBarGtk::AddBookmarkbarToBox(GtkWidget* box) { - gtk_box_pack_start(GTK_BOX(box), event_box_.get(), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(box), widget(), FALSE, FALSE, 0); } void BookmarkBarGtk::Show(bool animate) { - gtk_widget_show_all(event_box_.get()); + gtk_widget_show_all(widget()); if (animate) { slide_animation_->Show(); } else { @@ -229,7 +232,7 @@ void BookmarkBarGtk::Hide(bool animate) { if (slide_animation_->IsShowing() && animate) { slide_animation_->Hide(); } else { - gtk_widget_hide(event_box_.get()); + gtk_widget_hide(widget()); slide_animation_->Reset(0); AnimationProgressed(slide_animation_.get()); } @@ -394,7 +397,7 @@ void BookmarkBarGtk::AnimationEnded(const Animation* animation) { DCHECK_EQ(animation, slide_animation_.get()); if (!slide_animation_->IsShowing()) - gtk_widget_hide(event_box_.get()); + gtk_widget_hide(widget()); } void BookmarkBarGtk::Observe(NotificationType type, @@ -482,6 +485,8 @@ void BookmarkBarGtk::ConnectFolderButtonEvents(GtkWidget* widget) { G_CALLBACK(OnButtonPressed), this); g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK(OnFolderClicked), this); + + ViewIDUtil::SetID(widget, VIEW_ID_BOOKMARK_MENU); } const BookmarkNode* BookmarkBarGtk::GetNodeForToolButton(GtkWidget* widget) { diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h index 3136527..53f7caa 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.h +++ b/chrome/browser/gtk/bookmark_bar_gtk.h @@ -12,6 +12,7 @@ #include "app/slide_animation.h" #include "base/scoped_ptr.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" +#include "chrome/browser/gtk/view_id_util.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/owned_widget_gtk.h" @@ -43,6 +44,9 @@ class BookmarkBarGtk : public AnimationDelegate, // Returns the current browser. Browser* browser() const { return browser_; } + // Returns the top level widget. + GtkWidget* widget() const { return event_box_.get(); } + // Sets the PageNavigator that is used when the user selects an entry on // the bookmark bar. void SetPageNavigator(PageNavigator* navigator); diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 2dd1260..61fbcea 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -28,6 +28,7 @@ #include "chrome/browser/gtk/standard_menus.h" #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" #include "chrome/browser/gtk/toolbar_star_toggle_gtk.h" +#include "chrome/browser/gtk/view_id_util.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -271,6 +272,21 @@ void BrowserToolbarGtk::Init(Profile* profile, gtk_widget_hide(home_->widget()); } } + + SetViewIDs(); +} + +void BrowserToolbarGtk::SetViewIDs() { + ViewIDUtil::SetID(widget(), VIEW_ID_TOOLBAR); + ViewIDUtil::SetID(back_->widget(), VIEW_ID_BACK_BUTTON); + ViewIDUtil::SetID(forward_->widget(), VIEW_ID_FORWARD_BUTTON); + ViewIDUtil::SetID(reload_->widget(), VIEW_ID_RELOAD_BUTTON); + ViewIDUtil::SetID(home_->widget(), VIEW_ID_HOME_BUTTON); + ViewIDUtil::SetID(star_->widget(), VIEW_ID_STAR_BUTTON); + ViewIDUtil::SetID(location_bar_->widget(), VIEW_ID_LOCATION_BAR); + ViewIDUtil::SetID(go_->widget(), VIEW_ID_GO_BUTTON); + ViewIDUtil::SetID(page_menu_button_.get(), VIEW_ID_PAGE_MENU); + ViewIDUtil::SetID(app_menu_button_.get(), VIEW_ID_APP_MENU); } void BrowserToolbarGtk::AddToolbarToBox(GtkWidget* box) { diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h index f4fb16d..58dd44a 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.h +++ b/chrome/browser/gtk/browser_toolbar_gtk.h @@ -43,6 +43,9 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, // to which we attach our accelerators. void Init(Profile* profile, GtkWindow* top_level_window); + // Set the various widgets' ViewIDs. + void SetViewIDs(); + // Adds this GTK toolbar into a sizing box. void AddToolbarToBox(GtkWidget* box); diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc index cfc37fe..a22dad6 100644 --- a/chrome/browser/gtk/find_bar_gtk.cc +++ b/chrome/browser/gtk/find_bar_gtk.cc @@ -19,6 +19,7 @@ #include "chrome/browser/gtk/slide_animator_gtk.h" #include "chrome/browser/gtk/tab_contents_container_gtk.h" #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" +#include "chrome/browser/gtk/view_id_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/gtk_util.h" #include "chrome/common/notification_service.h" @@ -92,6 +93,7 @@ FindBarGtk::FindBarGtk(Browser* browser) ignore_changed_signal_(false), current_fixed_width_(-1) { InitWidgets(); + ViewIDUtil::SetID(text_entry_, VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); dialog_background_.reset(new NineBox(browser->profile()->GetThemeProvider(), 0, IDR_THEME_TOOLBAR, 0, diff --git a/chrome/browser/gtk/tab_contents_container_gtk.cc b/chrome/browser/gtk/tab_contents_container_gtk.cc index f6cbb2e..ebae3a6 100644 --- a/chrome/browser/gtk/tab_contents_container_gtk.cc +++ b/chrome/browser/gtk/tab_contents_container_gtk.cc @@ -8,6 +8,7 @@ #include "base/gfx/native_widget_types.h" #include "chrome/browser/gtk/gtk_floating_container.h" #include "chrome/browser/gtk/status_bubble_gtk.h" +#include "chrome/browser/gtk/view_id_util.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" #include "chrome/common/notification_service.h" @@ -68,6 +69,8 @@ void TabContentsContainerGtk::Init() { gtk_widget_show(fixed_); gtk_widget_show(floating_.get()); + + ViewIDUtil::SetID(widget(), VIEW_ID_TAB_CONTAINER); } void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index f6ed7d8..803c026 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -722,6 +722,8 @@ void TabStripGtk::Init() { drop_indicator_width = gdk_pixbuf_get_width(drop_image); drop_indicator_height = gdk_pixbuf_get_height(drop_image); } + + ViewIDUtil::SetDelegateForWidget(widget(), this); } void TabStripGtk::Show() { @@ -849,6 +851,26 @@ gfx::Point TabStripGtk::GetTabStripOriginForWidget(GtkWidget* target) { } //////////////////////////////////////////////////////////////////////////////// +// ViewIDUtil::Delegate implementation + +GtkWidget* TabStripGtk::GetWidgetForViewID(ViewID view_id) { + if (GetTabCount() > 0) { + if (view_id == VIEW_ID_TAB_LAST) { + return GetTabAt(GetTabCount() - 1)->widget(); + } else if ((view_id >= VIEW_ID_TAB_0) && (view_id < VIEW_ID_TAB_LAST)) { + int index = view_id - VIEW_ID_TAB_0; + if (index >= 0 && index < GetTabCount()) { + return GetTabAt(index)->widget(); + } else { + return NULL; + } + } + } + + return NULL; +} + +//////////////////////////////////////////////////////////////////////////////// // TabStripGtk, TabStripModelObserver implementation: void TabStripGtk::TabInsertedAt(TabContents* contents, diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.h b/chrome/browser/gtk/tabs/tab_strip_gtk.h index 69e4372..5445654 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.h +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.h @@ -13,6 +13,7 @@ #include "base/task.h" #include "base/message_loop.h" #include "chrome/browser/gtk/tabs/tab_gtk.h" +#include "chrome/browser/gtk/view_id_util.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/common/notification_observer.h" #include "chrome/common/owned_widget_gtk.h" @@ -24,7 +25,8 @@ class GtkThemeProvider; class TabStripGtk : public TabStripModelObserver, public TabGtk::TabDelegate, public MessageLoopForUI::Observer, - public NotificationObserver { + public NotificationObserver, + public ViewIDUtil::Delegate { public: class TabAnimation; @@ -86,6 +88,9 @@ class TabStripGtk : public TabStripModelObserver, // allocated. gfx::Point GetTabStripOriginForWidget(GtkWidget* widget); + // ViewIDUtil::Delegate implementation --------------------------------------- + virtual GtkWidget* GetWidgetForViewID(ViewID id); + protected: // TabStripModelObserver implementation: virtual void TabInsertedAt(TabContents* contents, diff --git a/chrome/browser/gtk/view_id_util.cc b/chrome/browser/gtk/view_id_util.cc new file mode 100644 index 0000000..fe6501f --- /dev/null +++ b/chrome/browser/gtk/view_id_util.cc @@ -0,0 +1,72 @@ +// 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/view_id_util.h" + +#include <stdint.h> + +#include <gtk/gtk.h> + +namespace { + +const char kViewIDString[] = "__VIEW_ID__"; +const char kViewIDOverrideString[] = "__VIEW_ID_OVERRIDE__"; + +struct ViewIDSearchStruct { + ViewID id; // Input: the ID we are searching for. + GtkWidget* widget; // Output: the found widget, or NULL. +}; + +// Recursively search for the given view ID among the children of |widget|. +void SearchForWidgetWithViewID(GtkWidget* widget, gpointer data) { + ViewIDSearchStruct* search_struct = + reinterpret_cast<ViewIDSearchStruct*>(data); + + // The widget has already been found; abort the search. + if (search_struct->widget) + return; + + // Check if the widget defines its own ID function. + ViewIDUtil::Delegate* delegate = reinterpret_cast<ViewIDUtil::Delegate*>( + g_object_get_data(G_OBJECT(widget), kViewIDOverrideString)); + if (delegate) { + search_struct->widget = delegate->GetWidgetForViewID(search_struct->id); + // If there was success, return. + if (search_struct->widget) + return; + } + + // Otherwise check the g_object data. + int widget_id = + reinterpret_cast<intptr_t>(g_object_get_data(G_OBJECT(widget), + kViewIDString)); + if (search_struct->id == widget_id) { + // Success; set |widget| and return. + search_struct->widget = widget; + return; + } + + // Recurse. + if (GTK_IS_CONTAINER(widget)) { + gtk_container_foreach(GTK_CONTAINER(widget), + SearchForWidgetWithViewID, data); + } +} + +} // namespace + +void ViewIDUtil::SetID(GtkWidget* widget, ViewID id) { + g_object_set_data(G_OBJECT(widget), kViewIDString, + reinterpret_cast<void*>(id)); +} + +GtkWidget* ViewIDUtil::GetWidget(GtkWidget* root, ViewID id) { + ViewIDSearchStruct search_struct = { id, NULL }; + SearchForWidgetWithViewID(root, &search_struct); + return search_struct.widget; +} + +void ViewIDUtil::SetDelegateForWidget(GtkWidget* widget, Delegate* delegate) { + g_object_set_data(G_OBJECT(widget), kViewIDOverrideString, delegate); +} diff --git a/chrome/browser/gtk/view_id_util.h b/chrome/browser/gtk/view_id_util.h new file mode 100644 index 0000000..1ec65e8 --- /dev/null +++ b/chrome/browser/gtk/view_id_util.h @@ -0,0 +1,27 @@ +// 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_VIEW_ID_UTIL_H_ +#define CHROME_BROWSER_GTK_VIEW_ID_UTIL_H_ + +#include "chrome/browser/view_ids.h" + +typedef struct _GtkWidget GtkWidget; + +class ViewIDUtil { + public: + // Use this delegate to override default view id searches. + class Delegate { + public: + virtual GtkWidget* GetWidgetForViewID(ViewID id) = 0; + }; + + static void SetID(GtkWidget* widget, ViewID id); + + static GtkWidget* GetWidget(GtkWidget* root, ViewID id); + + static void SetDelegateForWidget(GtkWidget* widget, Delegate* delegate); +}; + +#endif // CHROME_BROWSER_GTK_VIEW_ID_UTIL_H_ diff --git a/chrome/browser/gtk/view_id_util_unittest.cc b/chrome/browser/gtk/view_id_util_unittest.cc new file mode 100644 index 0000000..6c3d784 --- /dev/null +++ b/chrome/browser/gtk/view_id_util_unittest.cc @@ -0,0 +1,43 @@ +// 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/browser.h" +#include "chrome/browser/browser_window.h" +#include "chrome/browser/gtk/view_id_util.h" +#include "chrome/test/in_process_browser_test.h" + +class ViewIDTest : public InProcessBrowserTest { + public: + ViewIDTest() : root_window_(NULL) {} + + void CheckViewID(ViewID id, bool should_have) { + if (!root_window_) + root_window_ = GTK_WIDGET(browser()->window()->GetNativeHandle()); + + ASSERT_TRUE(root_window_); + EXPECT_EQ(should_have, !!ViewIDUtil::GetWidget(root_window_, id)); + } + + private: + GtkWidget* root_window_; +}; + +IN_PROC_BROWSER_TEST_F(ViewIDTest, Basic) { + for (int i = VIEW_ID_TOOLBAR; i < VIEW_ID_PREDEFINED_COUNT; ++i) { + CheckViewID(static_cast<ViewID>(i), true); + } + + CheckViewID(VIEW_ID_PREDEFINED_COUNT, false); +} + +IN_PROC_BROWSER_TEST_F(ViewIDTest, Delegate) { + CheckViewID(VIEW_ID_TAB_0, true); + CheckViewID(VIEW_ID_TAB_1, false); + + browser()->OpenURL(GURL("about:blank"), GURL(""), + NEW_BACKGROUND_TAB, PageTransition::TYPED); + + CheckViewID(VIEW_ID_TAB_0, true); + CheckViewID(VIEW_ID_TAB_1, true); +} |