summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 22:35:40 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 22:35:40 +0000
commit6bc080954611da13cfba38879e96792c079d1a95 (patch)
tree9cd29e2c9faa988cf6dbcf9024b832776509759d /chrome
parent005afbdc6836ecd6b3a09ab76b00221201830210 (diff)
downloadchromium_src-6bc080954611da13cfba38879e96792c079d1a95.zip
chromium_src-6bc080954611da13cfba38879e96792c079d1a95.tar.gz
chromium_src-6bc080954611da13cfba38879e96792c079d1a95.tar.bz2
Make the views bookmark bubble work on GTK.
The combobox still isn't implemented, but this makes TextBox work, and also does some changes around the info_bubble to make sure it get created properly. TEST=none BUG=none. Review URL: http://codereview.chromium.org/177026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/views/bookmark_bubble_view.cc20
-rw-r--r--chrome/browser/views/bookmark_bubble_view.h2
-rw-r--r--chrome/browser/views/dialog_stubs_gtk.cc18
-rw-r--r--chrome/browser/views/info_bubble.cc44
-rw-r--r--chrome/browser/views/info_bubble.h10
-rw-r--r--chrome/chrome.gyp2
6 files changed, 60 insertions, 36 deletions
diff --git a/chrome/browser/views/bookmark_bubble_view.cc b/chrome/browser/views/bookmark_bubble_view.cc
index 8a21fe3..545eb4a6 100644
--- a/chrome/browser/views/bookmark_bubble_view.cc
+++ b/chrome/browser/views/bookmark_bubble_view.cc
@@ -7,6 +7,7 @@
#include "app/gfx/canvas.h"
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
+#include "base/keyboard_codes.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/bookmarks/bookmark_editor.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
@@ -20,6 +21,7 @@
#include "views/standard_layout.h"
#include "views/controls/button/native_button.h"
#include "views/controls/textfield/textfield.h"
+#include "views/focus/focus_manager.h"
using views::Combobox;
using views::ColumnSet;
@@ -111,7 +113,7 @@ int BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemCount() {
std::wstring BookmarkBubbleView::RecentlyUsedFoldersModel::GetItemAt(
int index) {
- if (index == nodes_.size())
+ if (index == static_cast<int>(nodes_.size()))
return l10n_util::GetString(IDS_BOOMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER);
return nodes_[index]->GetTitle();
}
@@ -182,7 +184,7 @@ void BookmarkBubbleView::DidChangeBounds(const gfx::Rect& previous,
void BookmarkBubbleView::BubbleShown() {
DCHECK(GetWidget());
GetFocusManager()->RegisterAccelerator(
- views::Accelerator(VK_RETURN, false, false, false), this);
+ views::Accelerator(base::VKEY_RETURN, false, false, false), this);
title_tf_->RequestFocus();
title_tf_->SelectAll();
@@ -190,7 +192,7 @@ void BookmarkBubbleView::BubbleShown() {
bool BookmarkBubbleView::AcceleratorPressed(
const views::Accelerator& accelerator) {
- if (accelerator.GetKeyCode() != VK_RETURN)
+ if (accelerator.GetKeyCode() != base::VKEY_RETURN)
return false;
if (edit_button_->HasFocus())
ButtonPressed(edit_button_);
@@ -199,6 +201,12 @@ bool BookmarkBubbleView::AcceleratorPressed(
return true;
}
+void BookmarkBubbleView::ViewHierarchyChanged(bool is_add, View* parent,
+ View* child) {
+ if (is_add && child == this)
+ Init();
+}
+
BookmarkBubbleView::BookmarkBubbleView(InfoBubbleDelegate* delegate,
Profile* profile,
const GURL& url,
@@ -212,7 +220,6 @@ BookmarkBubbleView::BookmarkBubbleView(InfoBubbleDelegate* delegate,
profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url)),
remove_bookmark_(false),
apply_edits_(true) {
- Init();
}
void BookmarkBubbleView::Init() {
@@ -378,6 +385,7 @@ void BookmarkBubbleView::ShowEditor() {
// Commit any edits now.
ApplyEdits();
+#if defined(OS_WIN)
// Parent the editor to our root ancestor (not the root we're in, as that
// is the info bubble and will close shortly).
HWND parent = GetAncestor(GetWidget()->GetNativeView(), GA_ROOTOWNER);
@@ -390,6 +398,10 @@ void BookmarkBubbleView::ShowEditor() {
// status changes. That way, when the editor closes, activation is properly
// restored to the browser.
ShowWindow(GetWidget()->GetNativeView(), SW_HIDE);
+#else
+ NOTIMPLEMENTED(); // TODO(brettw) find the parent.
+ gfx::NativeView parent = NULL;
+#endif
// Even though we just hid the window, we need to invoke Close to schedule
// the delete and all that.
diff --git a/chrome/browser/views/bookmark_bubble_view.h b/chrome/browser/views/bookmark_bubble_view.h
index ebcc445..0c1d9e8 100644
--- a/chrome/browser/views/bookmark_bubble_view.h
+++ b/chrome/browser/views/bookmark_bubble_view.h
@@ -57,6 +57,8 @@ class BookmarkBubbleView : public views::View,
// Override to close on return.
virtual bool AcceleratorPressed(const views::Accelerator& accelerator);
+ virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
+
private:
// Model for the combobox showing the list of folders to choose from. The
// list always contains the bookmark bar, other node and parent. The list
diff --git a/chrome/browser/views/dialog_stubs_gtk.cc b/chrome/browser/views/dialog_stubs_gtk.cc
index 3a482ee..f57446d 100644
--- a/chrome/browser/views/dialog_stubs_gtk.cc
+++ b/chrome/browser/views/dialog_stubs_gtk.cc
@@ -32,24 +32,6 @@ void ShowImporterView(views::Widget* parent,
NOTIMPLEMENTED();
}
-void ShowBookmarkBubbleView(views::Window* parent,
- const gfx::Rect& bounds,
- InfoBubbleDelegate* delegate,
- Profile* profile,
- const GURL& url,
- bool newly_bookmarked) {
- NOTIMPLEMENTED();
-}
-
-void HideBookmarkBubbleView() {
- NOTIMPLEMENTED();
-}
-
-bool IsBookmarkBubbleViewShowing() {
- NOTIMPLEMENTED();
- return false;
-}
-
void ShowBookmarkManagerView(Profile* profile) {
NOTIMPLEMENTED();
}
diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc
index a4d57ff..a235de3 100644
--- a/chrome/browser/views/info_bubble.cc
+++ b/chrome/browser/views/info_bubble.cc
@@ -129,29 +129,29 @@ void InfoBubble::Init(views::Window* parent,
0 : CS_DROPSHADOW);
#endif
content_view_ = CreateContentView(content);
- gfx::Rect bounds =
- content_view_->CalculateWindowBoundsAndAjust(position_relative_to);
#if defined(OS_WIN)
- WidgetWin::Init(parent->GetNativeWindow(), bounds);
+ WidgetWin::Init(parent->GetNativeWindow(), gfx::Rect());
#else
- WidgetGtk::Init(GTK_WIDGET(parent->GetNativeWindow()), bounds);
+ WidgetGtk::Init(GTK_WIDGET(parent->GetNativeWindow()), gfx::Rect());
#endif
+
SetContentsView(content_view_);
// The preferred size may differ when parented. Ask for the bounds again
// and if they differ reset the bounds.
gfx::Rect parented_bounds =
content_view_->CalculateWindowBoundsAndAjust(position_relative_to);
- if (bounds != parented_bounds) {
+ // TODO(beng): This should be done in a cleaner and cross-platform way.
#if defined(OS_WIN)
- SetWindowPos(NULL, parented_bounds.x(), parented_bounds.y(),
- parented_bounds.width(), parented_bounds.height(),
- SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER);
- // Invoke ChangeSize, otherwise layered window isn't updated correctly.
- ChangeSize(0, CSize(parented_bounds.width(), parented_bounds.height()));
+ SetWindowPos(NULL, parented_bounds.x(), parented_bounds.y(),
+ parented_bounds.width(), parented_bounds.height(),
+ SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER);
+ // Invoke ChangeSize, otherwise layered window isn't updated correctly.
+ ChangeSize(0, CSize(parented_bounds.width(), parented_bounds.height()));
+#else
+ SetBounds(parented_bounds);
#endif
- }
#if defined(OS_WIN)
// Register the Escape accelerator for closing.
@@ -213,6 +213,7 @@ void InfoBubble::OnActivate(UINT action, BOOL minimized, HWND window) {
}
void InfoBubble::OnSize(UINT param, const CSize& size) {
+ // See OnSizeAllocate for the Linux version.
gfx::Path path;
content_view_->GetMask(gfx::Size(size.cx, size.cy), &path);
SetWindowRgn(path.CreateHRGN(), TRUE);
@@ -239,16 +240,26 @@ void InfoBubble::Close(bool closed_by_escape) {
#endif
}
+#if defined(OS_LINUX)
+void InfoBubble::OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) {
+ gfx::Path path;
+ content_view_->GetMask(gfx::Size(allocation->width, allocation->height),
+ &path);
+ SetShape(path);
+ WidgetGtk::OnSizeAllocate(widget, allocation);
+}
+#endif
+
// ContentView ----------------------------------------------------------------
InfoBubble::ContentView::ContentView(views::View* content, InfoBubble* host)
- : host_(host) {
+ : content_(content),
+ host_(host) {
if (UILayoutIsRightToLeft()) {
arrow_edge_ = TOP_RIGHT;
} else {
arrow_edge_ = TOP_LEFT;
}
- AddChildView(content);
}
gfx::Rect InfoBubble::ContentView::CalculateWindowBoundsAndAjust(
@@ -439,6 +450,13 @@ void InfoBubble::ContentView::Paint(gfx::Canvas* canvas) {
}
}
+void InfoBubble::ContentView::ViewHierarchyChanged(bool is_add,
+ View* parent,
+ View* child) {
+ if (is_add && child == this)
+ AddChildView(content_);
+}
+
gfx::Rect InfoBubble::ContentView::CalculateWindowBounds(
const gfx::Rect& position_relative_to) {
gfx::Size pref = GetPreferredSize();
diff --git a/chrome/browser/views/info_bubble.h b/chrome/browser/views/info_bubble.h
index 42e36fb..d50ca3c 100644
--- a/chrome/browser/views/info_bubble.h
+++ b/chrome/browser/views/info_bubble.h
@@ -147,12 +147,15 @@ class InfoBubble : public views::WidgetGtk, public AnimationDelegate {
// view. If this returns false the arrow is positioned along the right edge.
bool IsLeft() { return (arrow_edge_ & 1) == 0; }
- private:
+ virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
+ private:
// Returns the bounds for the window containing us based on the current
// arrow edge.
gfx::Rect CalculateWindowBounds(const gfx::Rect& position_relative_to);
+ views::View* content_;
+
// Edge to draw the arrow at.
ArrowEdge arrow_edge_;
@@ -170,6 +173,11 @@ class InfoBubble : public views::WidgetGtk, public AnimationDelegate {
// the close is the result of pressing escape.
void Close(bool closed_by_escape);
+#if defined(OS_LINUX)
+ // Overridden from WidgetGtk.
+ virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation);
+#endif
+
// The delegate notified when the InfoBubble is closed.
InfoBubbleDelegate* delegate_;
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 665d24f..62b1aa9 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -2361,6 +2361,8 @@
['include', '^browser/views/autocomplete/autocomplete_popup_gtk.h'],
['include', '^browser/views/bookmark_bar_view.cc'],
['include', '^browser/views/bookmark_bar_view.h'],
+ ['include', '^browser/views/bookmark_bubble_view.cc'],
+ ['include', '^browser/views/bookmark_bubble_view.h'],
['include', '^browser/views/bookmark_context_menu.cc'],
['include', '^browser/views/bookmark_context_menu.h'],
['include', '^browser/views/bookmark_menu_button.cc'],