summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/compact_location_bar_host.cc5
-rw-r--r--chrome/browser/chromeos/compact_location_bar_host.h4
-rw-r--r--chrome/browser/chromeos/compact_location_bar_view.cc88
-rw-r--r--chrome/browser/chromeos/compact_location_bar_view.h24
-rw-r--r--chrome/browser/chromeos/frame/browser_view.cc16
-rw-r--r--chrome/browser/chromeos/frame/browser_view.h2
6 files changed, 133 insertions, 6 deletions
diff --git a/chrome/browser/chromeos/compact_location_bar_host.cc b/chrome/browser/chromeos/compact_location_bar_host.cc
index eaba6ef..a412cb6 100644
--- a/chrome/browser/chromeos/compact_location_bar_host.cc
+++ b/chrome/browser/chromeos/compact_location_bar_host.cc
@@ -22,6 +22,7 @@
#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/browser/views/tabs/tab.h"
#include "chrome/browser/views/tabs/tab_strip.h"
+#include "chrome/browser/views/toolbar_star_toggle.h"
#include "views/controls/scrollbar/native_scroll_bar.h"
#include "views/focus/external_focus_tracker.h"
#include "views/focus/view_storage.h"
@@ -267,6 +268,10 @@ void CompactLocationBarHost::SetEnabled(bool enabled) {
}
}
+ToolbarStarToggle* CompactLocationBarHost::GetStarButton() {
+ return GetClbView()->star_button();
+}
+
void CompactLocationBarHost::Show(bool a) {
MessageLoopForUI::current()->AddObserver(mouse_observer_.get());
DropdownBarHost::Show(a);
diff --git a/chrome/browser/chromeos/compact_location_bar_host.h b/chrome/browser/chromeos/compact_location_bar_host.h
index 7ec6a25..e6816fc 100644
--- a/chrome/browser/chromeos/compact_location_bar_host.h
+++ b/chrome/browser/chromeos/compact_location_bar_host.h
@@ -16,6 +16,7 @@
class BrowserView;
class TabContents;
class Tab;
+class ToolbarStarToggle;
namespace chromeos {
@@ -60,6 +61,9 @@ class CompactLocationBarHost : public DropdownBarHost,
// Enable/disable the compact location bar.
void SetEnabled(bool enabled);
+ // Returns the star button for compact location bar.
+ ToolbarStarToggle* GetStarButton();
+
// Overridden from DropdownBarhost.
virtual void Show(bool animate);
virtual void Hide(bool animate);
diff --git a/chrome/browser/chromeos/compact_location_bar_view.cc b/chrome/browser/chromeos/compact_location_bar_view.cc
index 9f7c066..af803e4 100644
--- a/chrome/browser/chromeos/compact_location_bar_view.cc
+++ b/chrome/browser/chromeos/compact_location_bar_view.cc
@@ -8,8 +8,10 @@
#include <algorithm>
#include "app/l10n_util.h"
+#include "app/drag_drop_types.h"
#include "app/resource_bundle.h"
#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/bookmarks/bookmark_drag_data.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
#include "chrome/browser/browser_list.h"
@@ -22,6 +24,7 @@
#include "chrome/browser/views/browser_actions_container.h"
#include "chrome/browser/views/event_utils.h"
#include "chrome/browser/views/frame/browser_view.h"
+#include "chrome/browser/views/toolbar_star_toggle.h"
#include "gfx/canvas.h"
#include "gfx/point.h"
#include "grit/chromium_strings.h"
@@ -30,10 +33,12 @@
#include "views/background.h"
#include "views/controls/button/image_button.h"
#include "views/controls/native/native_view_host.h"
+#include "views/drag_utils.h"
#include "views/widget/widget.h"
#include "views/window/window.h"
namespace chromeos {
+const int kAutocompletePopupWidth = 700;
const int kDefaultLocationEntryWidth = 250;
const int kCompactLocationLeftMargin = 5;
const int kCompactLocationRightMargin = 10;
@@ -46,7 +51,8 @@ const int kWidgetsSeparatorWidth = 2;
CompactLocationBarView::CompactLocationBarView(CompactLocationBarHost* host)
: DropdownBarView(host),
reload_(NULL),
- browser_actions_(NULL) {
+ browser_actions_(NULL),
+ star_(NULL) {
SetFocusable(true);
}
@@ -95,7 +101,7 @@ void CompactLocationBarView::Init() {
reload_->SetImage(views::CustomButton::BS_PUSHED,
tp->GetBitmapNamed(IDR_RELOAD_P));
reload_->SetBackground(color, background,
- tp->GetBitmapNamed(IDR_RELOAD_MASK));
+ tp->GetBitmapNamed(IDR_BUTTON_MASK));
AddChildView(reload_);
@@ -114,6 +120,14 @@ void CompactLocationBarView::Init() {
location_entry_view_->set_focus_view(this);
location_entry_view_->Attach(location_entry_->GetNativeView());
+ star_ = new ToolbarStarToggle(this);
+ star_->SetDragController(this);
+ star_->set_profile(browser()->profile());
+ star_->set_host_view(this);
+ star_->set_bubble_positioner(this);
+ star_->Init();
+ AddChildView(star_);
+
location_entry_->Update(browser()->GetSelectedTabContents());
// Note: we tell the BrowserActionsContainer not to save its size because
@@ -131,12 +145,15 @@ gfx::Size CompactLocationBarView::GetPreferredSize() {
return gfx::Size(); // Not initialized yet, do nothing.
gfx::Size reload_size = reload_->GetPreferredSize();
+ gfx::Size star_size = star_->GetPreferredSize();
gfx::Size location_size = location_entry_view_->GetPreferredSize();
gfx::Size ba_size = browser_actions_->GetPreferredSize();
- int width = kCompactLocationLeftMargin + reload_size.width() +
+ int width =
+ reload_size.width() + kEntryLeftMargin + star_size.width() +
std::max(kDefaultLocationEntryWidth,
location_entry_view_->GetPreferredSize().width()) +
ba_size.width() +
+ kCompactLocationLeftMargin +
kCompactLocationRightMargin;
return gfx::Size(width, kDefaultLocationBarHeight);
}
@@ -151,7 +168,12 @@ void CompactLocationBarView::Layout() {
int reload_y = (height() - reload_size.height()) / 2;
reload_->SetBounds(cur_x, reload_y,
reload_size.width(), reload_size.height());
- cur_x += reload_size.width();
+ cur_x += reload_size.width() + kEntryLeftMargin;
+
+ gfx::Size star_size = star_->GetPreferredSize();
+ int star_y = (height() - star_size.height()) / 2;
+ star_->SetBounds(cur_x, star_y, star_size.width(), star_size.height());
+ cur_x += star_size.width();
gfx::Size ba_size = browser_actions_->GetPreferredSize();
int ba_y = (height() - ba_size.height()) / 2;
@@ -245,4 +267,62 @@ std::wstring CompactLocationBarView::GetTitle() const {
return std::wstring();
}
+////////////////////////////////////////////////////////////////////////////////
+// BubblePositioner overrides:
+gfx::Rect CompactLocationBarView::GetLocationStackBounds() const {
+ gfx::Point lower_left(0, height());
+ ConvertPointToScreen(this, &lower_left);
+ gfx::Rect popup = gfx::Rect(lower_left.x(), lower_left.y(),
+ kAutocompletePopupWidth, 0);
+ return popup.AdjustToFit(GetWidget()->GetWindow()->GetBounds());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// views::DragController overrides:
+void CompactLocationBarView::WriteDragData(views::View* sender,
+ const gfx::Point& press_pt,
+ OSExchangeData* data) {
+ DCHECK(GetDragOperations(sender, press_pt) != DragDropTypes::DRAG_NONE);
+
+ UserMetrics::RecordAction(UserMetricsAction("CompactLocationBar_DragStar"),
+ browser()->profile());
+
+ // If there is a bookmark for the URL, add the bookmark drag data for it. We
+ // do this to ensure the bookmark is moved, rather than creating an new
+ // bookmark.
+ TabContents* tab = browser()->GetSelectedTabContents();
+ if (tab) {
+ Profile* profile = browser()->profile();
+ if (profile && profile->GetBookmarkModel()) {
+ const BookmarkNode* node = profile->GetBookmarkModel()->
+ GetMostRecentlyAddedNodeForURL(tab->GetURL());
+ if (node) {
+ BookmarkDragData bookmark_data(node);
+ bookmark_data.Write(profile, data);
+ }
+ }
+
+ drag_utils::SetURLAndDragImage(tab->GetURL(),
+ UTF16ToWideHack(tab->GetTitle()),
+ tab->GetFavIcon(),
+ data);
+ }
+}
+
+int CompactLocationBarView::GetDragOperations(views::View* sender,
+ const gfx::Point& p) {
+ DCHECK(sender == star_);
+ TabContents* tab = browser()->GetSelectedTabContents();
+ if (!tab || !tab->ShouldDisplayURL() || !tab->GetURL().is_valid()) {
+ return DragDropTypes::DRAG_NONE;
+ }
+ Profile* profile = browser()->profile();
+ if (profile && profile->GetBookmarkModel() &&
+ profile->GetBookmarkModel()->IsBookmarked(tab->GetURL())) {
+ return DragDropTypes::DRAG_MOVE | DragDropTypes::DRAG_COPY |
+ DragDropTypes::DRAG_LINK;
+ }
+ return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK;
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/compact_location_bar_view.h b/chrome/browser/chromeos/compact_location_bar_view.h
index ec284b0..e4f8d73 100644
--- a/chrome/browser/chromeos/compact_location_bar_view.h
+++ b/chrome/browser/chromeos/compact_location_bar_view.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_VIEW_H_
#include "base/basictypes.h"
+#include "chrome/browser/bubble_positioner.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/chromeos/compact_location_bar_host.h"
#include "chrome/browser/views/dropdown_bar_view.h"
@@ -16,9 +17,11 @@ class AutocompleteEditViewGtk;
class Browser;
class BrowserActionsContainer;
class BrowserView;
+class ToolbarStarToggleGtk;
class Tab;
class TabContents;
class TabStrip;
+class ToolbarStarToggle;
namespace views {
class ImageButton;
@@ -32,7 +35,9 @@ namespace chromeos {
// navigation bar mode.
class CompactLocationBarView : public DropdownBarView,
public views::ButtonListener,
- public AutocompleteEditController {
+ public AutocompleteEditController,
+ public BubblePositioner,
+ public views::DragController {
public:
explicit CompactLocationBarView(CompactLocationBarHost* host);
~CompactLocationBarView();
@@ -42,6 +47,8 @@ class CompactLocationBarView : public DropdownBarView,
void Update(const TabContents* contents);
+ ToolbarStarToggle* star_button() const { return star_; }
+
private:
Browser* browser() const;
@@ -74,6 +81,20 @@ class CompactLocationBarView : public DropdownBarView,
virtual SkBitmap GetFavIcon() const;
virtual std::wstring GetTitle() const;
+ // BubblePositioner implementation.
+ virtual gfx::Rect GetLocationStackBounds() const;
+
+ // views::DragController implementation.
+ virtual void WriteDragData(View* sender,
+ const gfx::Point& press_pt,
+ OSExchangeData* data);
+ virtual int GetDragOperations(View* sender, const gfx::Point& p);
+ virtual bool CanStartDrag(View* sender,
+ const gfx::Point& press_pt,
+ const gfx::Point& p) {
+ return true;
+ }
+
CompactLocationBarHost* clb_host() {
return static_cast<CompactLocationBarHost*>(host());
}
@@ -82,6 +103,7 @@ class CompactLocationBarView : public DropdownBarView,
scoped_ptr<AutocompleteEditViewGtk> location_entry_;
views::NativeViewHost* location_entry_view_;
BrowserActionsContainer* browser_actions_;
+ ToolbarStarToggle* star_;
DISALLOW_COPY_AND_ASSIGN(CompactLocationBarView);
};
diff --git a/chrome/browser/chromeos/frame/browser_view.cc b/chrome/browser/chromeos/frame/browser_view.cc
index eb2029c..254be1d 100644
--- a/chrome/browser/chromeos/frame/browser_view.cc
+++ b/chrome/browser/chromeos/frame/browser_view.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/views/tabs/tab.h"
#include "chrome/browser/views/tabs/tab_strip.h"
#include "chrome/browser/views/toolbar_view.h"
+#include "chrome/browser/views/toolbar_star_toggle.h"
#include "gfx/canvas.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -440,6 +441,19 @@ void BrowserView::ChildPreferredSizeChanged(View* child) {
SchedulePaint();
}
+void BrowserView::SetStarredState(bool is_starred) {
+ ::BrowserView::SetStarredState(is_starred);
+ compact_location_bar_host_->GetStarButton()->SetToggled(is_starred);
+}
+
+void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {
+ if (is_compact_style())
+ compact_location_bar_host_->GetStarButton()->ShowStarBubble(
+ url, !already_bookmarked);
+ else
+ ::BrowserView::ShowBookmarkBubble(url, already_bookmarked);
+}
+
// views::ButtonListener overrides.
void BrowserView::ButtonPressed(views::Button* sender,
const views::Event& event) {
@@ -450,7 +464,7 @@ void BrowserView::ButtonPressed(views::Button* sender,
origin.Offset(kAppLauncherLeftPadding, 0);
views::RootView::ConvertPointToScreen(this, &origin);
bounds.set_origin(origin);
- ::AppLauncher::Show(browser(), bounds, gfx::Point());
+ ::AppLauncher::Show(browser(), bounds);
}
// views::ContextMenuController overrides.
diff --git a/chrome/browser/chromeos/frame/browser_view.h b/chrome/browser/chromeos/frame/browser_view.h
index cd868c7..0d3dd2a 100644
--- a/chrome/browser/chromeos/frame/browser_view.h
+++ b/chrome/browser/chromeos/frame/browser_view.h
@@ -66,6 +66,8 @@ class BrowserView : public ::BrowserView,
virtual views::LayoutManager* CreateLayoutManager() const;
virtual BaseTabStrip* CreateTabStrip(TabStripModel* tab_strip_model);
virtual void ChildPreferredSizeChanged(View* child);
+ virtual void SetStarredState(bool is_starred);
+ virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
// views::ButtonListener overrides.
virtual void ButtonPressed(views::Button* sender, const views::Event& event);