Home | History | Annotate | Download | only in views
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/views/pinned_contents_info_bubble.h"
      6 
      7 #include "chrome/browser/ui/views/bubble/bubble_border.h"
      8 
      9 void PinnedContentsBorderContents::SizeAndGetBounds(
     10     const gfx::Rect& position_relative_to,
     11     BubbleBorder::ArrowLocation arrow_location,
     12     bool allow_bubble_offscreen,
     13     const gfx::Size& contents_size,
     14     gfx::Rect* contents_bounds,
     15     gfx::Rect* window_bounds) {
     16   // Arrow offset is calculated from the middle of the |position_relative_to|.
     17   int offset = position_relative_to.x() + (position_relative_to.width() / 2);
     18   offset -= bubble_anchor_.x();
     19 
     20   gfx::Insets insets;
     21   bubble_border_->GetInsets(&insets);
     22   offset += kLeftMargin + insets.left() + 1;
     23   bubble_border_->SetArrowOffset(offset, contents_size);
     24 
     25   BorderContents::SizeAndGetBounds(
     26       position_relative_to, arrow_location,
     27       true,  // Don't move the bubble around if it does not fit on the screen.
     28       contents_size, contents_bounds, window_bounds);
     29 
     30   // Now move the y position to make sure the bubble contents overlap the view.
     31   window_bounds->Offset(0, -(kTopMargin + 1));
     32 }
     33 
     34 // Bubble -----------------------------------------------------------------
     35 
     36 // static
     37 PinnedContentsInfoBubble* PinnedContentsInfoBubble::Show(
     38     views::Widget* parent,
     39     const gfx::Rect& position_relative_to,
     40     BubbleBorder::ArrowLocation arrow_location,
     41     const gfx::Point& bubble_anchor,
     42     views::View* contents,
     43     BubbleDelegate* delegate) {
     44   PinnedContentsInfoBubble* bubble =
     45       new PinnedContentsInfoBubble(bubble_anchor);
     46   bubble->InitBubble(parent, position_relative_to, arrow_location,
     47                      contents, delegate);
     48   return bubble;
     49 }
     50 
     51 BorderContents* PinnedContentsInfoBubble::CreateBorderContents() {
     52   return new PinnedContentsBorderContents(bubble_anchor_);
     53 }
     54