diff options
author | sidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 20:49:45 +0000 |
---|---|---|
committer | sidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 20:49:45 +0000 |
commit | ad573f16ef06760e855f3e13ad0902d19449cbd6 (patch) | |
tree | 6217bcdb61c5f54758f2cb606bb2aa4ff97ad3c1 /chrome/browser/views/extensions | |
parent | a9d589c3000d0e72f32dcd47842374d306e29176 (diff) | |
download | chromium_src-ad573f16ef06760e855f3e13ad0902d19449cbd6.zip chromium_src-ad573f16ef06760e855f3e13ad0902d19449cbd6.tar.gz chromium_src-ad573f16ef06760e855f3e13ad0902d19449cbd6.tar.bz2 |
Infrastructure to allow putting Extension Shelf on top along with Bookmarks.
BUG=http://code.google.com/p/chromium/issues/detail?id=20517
TEST=none
Review URL: http://codereview.chromium.org/173613
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25236 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/extensions')
-rw-r--r-- | chrome/browser/views/extensions/extension_shelf.cc | 119 | ||||
-rw-r--r-- | chrome/browser/views/extensions/extension_shelf.h | 6 |
2 files changed, 69 insertions, 56 deletions
diff --git a/chrome/browser/views/extensions/extension_shelf.cc b/chrome/browser/views/extensions/extension_shelf.cc index 0d0fb0a..6841dc9 100644 --- a/chrome/browser/views/extensions/extension_shelf.cc +++ b/chrome/browser/views/extensions/extension_shelf.cc @@ -698,24 +698,7 @@ void ExtensionShelf::ToggleWhenExtensionShelfVisible(Profile* profile) { } gfx::Size ExtensionShelf::GetPreferredSize() { - if (!model_->count()) - return gfx::Size(0, 0); - - gfx::Size prefsize; - if (OnNewTabPage()) { - prefsize.set_height(kShelfHeight + static_cast<int>(static_cast<double> - (kNewtabShelfHeight - kShelfHeight) * - (1 - size_animation_->GetCurrentValue()))); - } else { - prefsize.set_height(static_cast<int>(static_cast<double>(kShelfHeight) * - size_animation_->GetCurrentValue())); - } - - // Width doesn't matter, we're always given a width based on the browser - // size. - prefsize.set_width(1); - - return prefsize; + return LayoutItems(true); } void ExtensionShelf::ChildPreferredSizeChanged(View* child) { @@ -726,46 +709,10 @@ void ExtensionShelf::ChildPreferredSizeChanged(View* child) { } void ExtensionShelf::Layout() { - if (!GetParent()) - return; - if (!model_) - return; - - int x = kLeftMargin; - int y = kTopMargin; - int content_height = kShelfHeight - kTopMargin - kBottomMargin; - int max_x = width() - kRightMargin; - - if (OnNewTabPage()) { - double current_state = 1 - size_animation_->GetCurrentValue(); - x += static_cast<int>(static_cast<double> - (kNewtabHorizontalPadding + kNewtabExtraHorMargin) * current_state); - y += static_cast<int>(static_cast<double> - (kNewtabVerticalPadding + kNewtabExtraVerMargin) * current_state); - max_x -= static_cast<int>(static_cast<double> - (kNewtabHorizontalPadding) * current_state); - } - - int count = model_->count(); - for (int i = 0; i < count; ++i) { - x += kToolstripPadding; // left padding - Toolstrip* toolstrip = ToolstripAtIndex(i); - if (!toolstrip) // can be NULL while in the process of removing - continue; - View* view = toolstrip->GetShelfView(); - gfx::Size pref = view->GetPreferredSize(); - int next_x = x + pref.width() + kToolstripPadding; // right padding - if (view == toolstrip->view()) - toolstrip->view()->set_is_clipped(next_x >= max_x); - view->SetBounds(x, y, pref.width(), content_height); - view->Layout(); - if (toolstrip->handle_visible()) - toolstrip->LayoutHandle(); - x = next_x + kToolstripDividerWidth; - } - SchedulePaint(); + LayoutItems(false); } + void ExtensionShelf::OnMouseEntered(const views::MouseEvent& event) { } @@ -1004,6 +951,66 @@ void ExtensionShelf::LoadFromModel() { ToolstripInsertedAt(model_->ToolstripAt(i).host, i); } +gfx::Size ExtensionShelf::LayoutItems(bool compute_bounds_only) { + if (!GetParent() || !model_ || !model_->count()) + return gfx::Size(0, 0); + + gfx::Size prefsize; + int x = kLeftMargin; + int y = kTopMargin; + int content_height = kShelfHeight - kTopMargin - kBottomMargin; + int max_x = width() - kRightMargin; + + if (OnNewTabPage()) { + double current_state = 1 - size_animation_->GetCurrentValue(); + x += static_cast<int>(static_cast<double> + (kNewtabHorizontalPadding + kNewtabExtraHorMargin) * current_state); + y += static_cast<int>(static_cast<double> + (kNewtabVerticalPadding + kNewtabExtraVerMargin) * current_state); + max_x -= static_cast<int>(static_cast<double> + (kNewtabHorizontalPadding) * current_state); + } + + int count = model_->count(); + for (int i = 0; i < count; ++i) { + x += kToolstripPadding; // left padding + Toolstrip* toolstrip = ToolstripAtIndex(i); + if (!toolstrip) // can be NULL while in the process of removing + continue; + View* view = toolstrip->GetShelfView(); + gfx::Size pref = view->GetPreferredSize(); + int next_x = x + pref.width() + kToolstripPadding; // right padding + if (!compute_bounds_only) { + if (view == toolstrip->view()) + toolstrip->view()->set_is_clipped(next_x >= max_x); + view->SetBounds(x, y, pref.width(), content_height); + view->Layout(); + if (toolstrip->handle_visible()) + toolstrip->LayoutHandle(); + } + x = next_x + kToolstripDividerWidth; + } + + if (!compute_bounds_only) + SchedulePaint(); + + if (compute_bounds_only) { + if (OnNewTabPage()) { + prefsize.set_height(kShelfHeight + static_cast<int>(static_cast<double> + (kNewtabShelfHeight - kShelfHeight) * + (1 - size_animation_->GetCurrentValue()))); + } else { + prefsize.set_height(static_cast<int>(static_cast<double>(kShelfHeight) * + size_animation_->GetCurrentValue())); + } + + x += kRightMargin; + prefsize.set_width(x); + } + + return prefsize; +} + bool ExtensionShelf::IsDetachedStyle() { return OnNewTabPage() && (size_animation_->GetCurrentValue() != 1); } diff --git a/chrome/browser/views/extensions/extension_shelf.h b/chrome/browser/views/extensions/extension_shelf.h index 08f3d1c..3f994e4 100644 --- a/chrome/browser/views/extensions/extension_shelf.h +++ b/chrome/browser/views/extensions/extension_shelf.h @@ -108,6 +108,12 @@ class ExtensionShelf : public views::View, // Loads initial state from |model_|. void LoadFromModel(); + // This method computes the bounds for the extension shelf items. If + // |compute_bounds_only| = TRUE, the bounds for the items are just computed, + // but are not set. This mode is used by GetPreferredSize() to obtain the + // desired bounds. If |compute_bounds_only| = FALSE, the bounds are set. + gfx::Size LayoutItems(bool compute_bounds_only); + // Returns whether the extension shelf always shown (checks pref value). bool IsAlwaysShown(); |