| Index: chrome/browser/ui/views/frame/contents_container.cc
|
| diff --git a/chrome/browser/ui/views/frame/contents_container.cc b/chrome/browser/ui/views/frame/contents_container.cc
|
| index 5943a7d32e5f31c09495898e52de7fde957a9e59..d528586bdd51527b63d24a5e5bdcbaf2f0881716 100644
|
| --- a/chrome/browser/ui/views/frame/contents_container.cc
|
| +++ b/chrome/browser/ui/views/frame/contents_container.cc
|
| @@ -15,33 +15,27 @@ const char ContentsContainer::kViewClassName[] =
|
|
|
| namespace {
|
|
|
| -int PreviewHeightInPixels(int parent_height, int preview_height,
|
| - InstantSizeUnits preview_height_units) {
|
| - preview_height = std::max(0, preview_height);
|
| - switch (preview_height_units) {
|
| - case INSTANT_SIZE_PERCENT:
|
| - return std::min(parent_height, (parent_height * preview_height) / 100);
|
| -
|
| - case INSTANT_SIZE_PIXELS:
|
| - return std::min(parent_height, preview_height);
|
| - }
|
| - NOTREACHED() << "unknown units: " << preview_height_units;
|
| - return 0;
|
| +int OverlayHeightInPixels(int parent_height,
|
| + int overlay_height,
|
| + bool is_height_in_pixels) {
|
| + overlay_height = std::max(0, overlay_height);
|
| + return std::min(parent_height, is_height_in_pixels ?
|
| + overlay_height : (parent_height * overlay_height) / 100);
|
| }
|
|
|
| -// This class draws the drop shadow below the preview when the non-NTP preview
|
| +// This class draws the drop shadow below the overlay when the non-NTP overlay
|
| // doesn't fill up the entire content page.
|
| // This class is owned by ContentsContainer, which:
|
| // - adds it as child when shadow is needed
|
| -// - removes it as child when shadow is not needed or when preview is nuked or
|
| -// when preview is removed as child
|
| +// - removes it as child when shadow is not needed or when overlay is nuked or
|
| +// when overlay is removed as child
|
| // - always makes sure it's the 3rd child in the view hierarchy i.e. after
|
| -// active and preview.
|
| +// active and overlay.
|
| class ShadowView : public views::View {
|
| public:
|
| ShadowView() {
|
| drop_shadow_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
|
| - IDR_PREVIEW_DROP_SHADOW);
|
| + IDR_OVERLAY_DROP_SHADOW);
|
|
|
| SetPaintToLayer(true);
|
| SetFillsBoundsOpaquely(false);
|
| @@ -76,12 +70,12 @@ class ShadowView : public views::View {
|
|
|
| ContentsContainer::ContentsContainer(views::WebView* active)
|
| : active_(active),
|
| - preview_(NULL),
|
| - preview_web_contents_(NULL),
|
| + overlay_(NULL),
|
| + overlay_web_contents_(NULL),
|
| draw_drop_shadow_(false),
|
| active_top_margin_(0),
|
| - preview_height_(100),
|
| - preview_height_units_(INSTANT_SIZE_PERCENT) {
|
| + overlay_height_(100),
|
| + is_height_in_pixels_(false) {
|
| AddChildView(active_);
|
| }
|
|
|
| @@ -89,29 +83,28 @@ ContentsContainer::~ContentsContainer() {
|
| RemoveShadowView(true);
|
| }
|
|
|
| -void ContentsContainer::MakePreviewContentsActiveContents() {
|
| - DCHECK(preview_);
|
| +void ContentsContainer::MakeOverlayContentsActiveContents() {
|
| + DCHECK(overlay_);
|
|
|
| - active_ = preview_;
|
| - preview_ = NULL;
|
| - preview_web_contents_ = NULL;
|
| - // Since |preview_| has been nuked, shadow view is not needed anymore.
|
| + active_ = overlay_;
|
| + overlay_ = NULL;
|
| + overlay_web_contents_ = NULL;
|
| + // Since |overlay_| has been nuked, shadow view is not needed anymore.
|
| // Note that the previous |active_| will be deleted by caller (see
|
| // BrowserView::ActiveTabChanged()) after this call, hence removing the old
|
| // |active_| as a child, and making the new |active_| (which is the previous
|
| - // |preview_|) the first child.
|
| + // |overlay_|) the first child.
|
| RemoveShadowView(true);
|
| Layout();
|
| }
|
|
|
| -void ContentsContainer::SetPreview(views::WebView* preview,
|
| - content::WebContents* preview_web_contents,
|
| - const chrome::search::Mode& search_mode,
|
| +void ContentsContainer::SetOverlay(views::WebView* overlay,
|
| + content::WebContents* overlay_web_contents,
|
| int height,
|
| - InstantSizeUnits units,
|
| + bool is_height_in_pixels,
|
| bool draw_drop_shadow) {
|
| // If drawing drop shadow, clip the bottom 1-px-thick separator out of
|
| - // preview.
|
| + // overlay.
|
| // TODO(kuan): remove this when GWS gives chrome the height without the
|
| // separator.
|
| #if !defined(OS_WIN)
|
| @@ -119,69 +112,54 @@ void ContentsContainer::SetPreview(views::WebView* preview,
|
| --height;
|
| #endif // !defined(OS_WIN)
|
|
|
| - if (preview_ == preview && preview_web_contents_ == preview_web_contents &&
|
| - search_mode_ == search_mode && preview_height_ == height &&
|
| - preview_height_units_ == units && draw_drop_shadow_ == draw_drop_shadow) {
|
| + if (overlay_ == overlay && overlay_web_contents_ == overlay_web_contents &&
|
| + overlay_height_ == height &&
|
| + is_height_in_pixels_ == is_height_in_pixels &&
|
| + draw_drop_shadow_ == draw_drop_shadow)
|
| return;
|
| - }
|
|
|
| - if (preview_ != preview) {
|
| - if (preview_) {
|
| + if (overlay_ != overlay) {
|
| + if (overlay_) {
|
| // Order of children is important: always |active_| first, then
|
| - // |preview_|, then shadow view if necessary. To make sure the next view
|
| - // is added in the right order, remove shadow view every time |preview_|
|
| + // |overlay_|, then shadow view if necessary. To make sure the next view
|
| + // is added in the right order, remove shadow view every time |overlay_|
|
| // is removed.
|
| RemoveShadowView(false);
|
| - RemoveChildView(preview_);
|
| + RemoveChildView(overlay_);
|
| }
|
| - preview_ = preview;
|
| - if (preview_)
|
| - AddChildView(preview_);
|
| + overlay_ = overlay;
|
| + if (overlay_)
|
| + AddChildView(overlay_);
|
| }
|
|
|
| - preview_web_contents_ = preview_web_contents;
|
| - search_mode_ = search_mode;
|
| - preview_height_ = height;
|
| - preview_height_units_ = units;
|
| + overlay_web_contents_ = overlay_web_contents;
|
| + overlay_height_ = height;
|
| + is_height_in_pixels_ = is_height_in_pixels;
|
| draw_drop_shadow_ = draw_drop_shadow;
|
|
|
| - // Add shadow view if there's preview and drop shadow is needed.
|
| - // Remove shadow view if there's no preview.
|
| - // If there's preview and drop shadow is not needed, that means the partial-
|
| - // height preview is going to be full-height. Don't remove the shadow view
|
| - // yet because its layered view will disappear before the non-layered preview
|
| - // is repainted at the full height, leaving no separator between the preview
|
| - // and active contents. When the preview is repainted at the full height, the
|
| + // Add shadow view if there's overlay and drop shadow is needed.
|
| + // Remove shadow view if there's no overlay.
|
| + // If there's overlay and drop shadow is not needed, that means the partial-
|
| + // height overlay is going to be full-height. Don't remove the shadow view
|
| + // yet because its layered view will disappear before the non-layered overlay
|
| + // is repainted at the full height, leaving no separator between the overlay
|
| + // and active contents. When the overlay is repainted at the full height, the
|
| // shadow view, which remains at the original position below the partial-
|
| - // height preview, will automatically be obscured the full-height preview.
|
| - if (preview_ && draw_drop_shadow_) {
|
| + // height overlay, will automatically be obscured by the full-height overlay.
|
| + if (overlay_ && draw_drop_shadow_) {
|
| #if !defined(OS_WIN)
|
| if (!shadow_view_.get()) // Shadow view has not been created.
|
| shadow_view_.reset(new ShadowView());
|
| if (!shadow_view_->parent()) // Shadow view has not been added.
|
| AddChildView(shadow_view_.get());
|
| #endif // !defined(OS_WIN)
|
| - } else if (!preview_) {
|
| + } else if (!overlay_) {
|
| RemoveShadowView(true);
|
| }
|
|
|
| Layout();
|
| }
|
|
|
| -void ContentsContainer::MaybeStackPreviewAtTop() {
|
| - if (!preview_)
|
| - return;
|
| - // To force |preview_| to the topmost in the z-order, remove it, then add it
|
| - // back.
|
| - // See comments in SetPreview() for why shadow view is removed.
|
| - bool removed_shadow = RemoveShadowView(false);
|
| - RemoveChildView(preview_);
|
| - AddChildView(preview_);
|
| - if (removed_shadow) // Add back shadow view if it was removed.
|
| - AddChildView(shadow_view_.get());
|
| - Layout();
|
| -}
|
| -
|
| void ContentsContainer::SetActiveTopMargin(int margin) {
|
| if (active_top_margin_ == margin)
|
| return;
|
| @@ -192,17 +170,16 @@ void ContentsContainer::SetActiveTopMargin(int margin) {
|
| InvalidateLayout();
|
| }
|
|
|
| -gfx::Rect ContentsContainer::GetPreviewBounds() const {
|
| +gfx::Rect ContentsContainer::GetOverlayBounds() const {
|
| gfx::Point screen_loc;
|
| ConvertPointToScreen(this, &screen_loc);
|
| return gfx::Rect(screen_loc, size());
|
| }
|
|
|
| -bool ContentsContainer::IsPreviewFullHeight(
|
| - int preview_height,
|
| - InstantSizeUnits preview_height_units) const {
|
| - int height_in_pixels = PreviewHeightInPixels(height(), preview_height,
|
| - preview_height_units);
|
| +bool ContentsContainer::IsOverlayFullHeight(int overlay_height,
|
| + bool is_height_in_pixels) const {
|
| + int height_in_pixels = OverlayHeightInPixels(height(), overlay_height,
|
| + is_height_in_pixels);
|
| return height_in_pixels == height();
|
| }
|
|
|
| @@ -212,14 +189,14 @@ void ContentsContainer::Layout() {
|
|
|
| active_->SetBounds(0, content_y, width(), content_height);
|
|
|
| - if (preview_) {
|
| - preview_->SetBounds(0, 0, width(),
|
| - PreviewHeightInPixels(height(), preview_height_,
|
| - preview_height_units_));
|
| + if (overlay_) {
|
| + overlay_->SetBounds(0, 0, width(),
|
| + OverlayHeightInPixels(height(), overlay_height_,
|
| + is_height_in_pixels_));
|
| if (draw_drop_shadow_) {
|
| #if !defined(OS_WIN)
|
| DCHECK(shadow_view_.get() && shadow_view_->parent());
|
| - shadow_view_->SetBounds(0, preview_->bounds().height(), width(),
|
| + shadow_view_->SetBounds(0, overlay_->bounds().height(), width(),
|
| shadow_view_->GetPreferredSize().height());
|
| #endif // !defined(OS_WIN)
|
| }
|
|
|