| OLD | NEW |
| (Empty) | |
| 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/dropdown_bar_view.h" |
| 6 |
| 7 #include "chrome/browser/themes/theme_service.h" |
| 8 #include "chrome/browser/ui/view_ids.h" |
| 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 10 #include "grit/generated_resources.h" |
| 11 #include "grit/theme_resources_standard.h" |
| 12 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/gfx/canvas.h" |
| 14 #include "views/background.h" |
| 15 #include "views/widget/widget.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 // When we are animating, we draw only the top part of the left and right |
| 20 // edges to give the illusion that the find dialog is attached to the |
| 21 // window during this animation; this is the height of the items we draw. |
| 22 const int kAnimatingEdgeHeight = 5; |
| 23 |
| 24 } // namespace |
| 25 |
| 26 DropdownBarView::DropdownBarView(DropdownBarHost* host) |
| 27 : host_(host), |
| 28 animation_offset_(0), |
| 29 dialog_left_(NULL), |
| 30 dialog_middle_(NULL), |
| 31 dialog_right_(NULL) { |
| 32 } |
| 33 |
| 34 DropdownBarView::~DropdownBarView() { |
| 35 } |
| 36 |
| 37 //////////////////////////////////////////////////////////////////////////////// |
| 38 // DropDownBarView, public: |
| 39 |
| 40 void DropdownBarView::SetAnimationOffset(int offset) { |
| 41 animation_offset_ = offset; |
| 42 } |
| 43 |
| 44 //////////////////////////////////////////////////////////////////////////////// |
| 45 // DropDownBarView, protected: |
| 46 |
| 47 void DropdownBarView::SetDialogBorderBitmaps(const SkBitmap* dialog_left, |
| 48 const SkBitmap* dialog_middle, |
| 49 const SkBitmap* dialog_right) { |
| 50 dialog_left_ = dialog_left; |
| 51 dialog_middle_ = dialog_middle; |
| 52 dialog_right_ = dialog_right; |
| 53 } |
| 54 |
| 55 gfx::Rect DropdownBarView::PaintOffsetToolbarBackground(gfx::Canvas* canvas) { |
| 56 // Determine the find bar size as well as the offset from which to tile the |
| 57 // toolbar background image. First, get the widget bounds. |
| 58 gfx::Rect bounds = GetWidget()->GetWindowScreenBounds(); |
| 59 // Now convert from screen to parent coordinates. |
| 60 gfx::Point origin(bounds.origin()); |
| 61 BrowserView* browser_view = host()->browser_view(); |
| 62 ConvertPointToView(NULL, browser_view, &origin); |
| 63 bounds.set_origin(origin); |
| 64 // Finally, calculate the background image tiling offset. |
| 65 origin = browser_view->OffsetPointForToolbarBackgroundImage(origin); |
| 66 |
| 67 // First, we draw the background image for the whole dialog (3 images: left, |
| 68 // middle and right). Note, that the window region has been set by the |
| 69 // controller, so the whitespace in the left and right background images is |
| 70 // actually outside the window region and is therefore not drawn. See |
| 71 // FindInPageWidgetWin::CreateRoundedWindowEdges() for details. |
| 72 ui::ThemeProvider* tp = GetThemeProvider(); |
| 73 canvas->TileImageInt(*tp->GetBitmapNamed(IDR_THEME_TOOLBAR), origin.x(), |
| 74 origin.y(), 0, 0, bounds.width(), bounds.height()); |
| 75 return bounds; |
| 76 } |
| 77 |
| 78 void DropdownBarView::PaintDialogBorder(gfx::Canvas* canvas, |
| 79 const gfx::Rect& bounds) const { |
| 80 DCHECK(dialog_left_); |
| 81 DCHECK(dialog_middle_); |
| 82 DCHECK(dialog_right_); |
| 83 |
| 84 canvas->DrawBitmapInt(*dialog_left_, 0, 0); |
| 85 |
| 86 // Stretch the middle background to cover all of the area between the two |
| 87 // other images. |
| 88 canvas->TileImageInt(*dialog_middle_, dialog_left_->width(), 0, |
| 89 bounds.width() - dialog_left_->width() - dialog_right_->width(), |
| 90 dialog_middle_->height()); |
| 91 |
| 92 canvas->DrawBitmapInt(*dialog_right_, bounds.width() - dialog_right_->width(), |
| 93 0); |
| 94 } |
| 95 |
| 96 void DropdownBarView::PaintAnimatingEdges(gfx::Canvas* canvas, |
| 97 const gfx::Rect& bounds) const { |
| 98 if (animation_offset() > 0) { |
| 99 // While animating we draw the curved edges at the point where the |
| 100 // controller told us the top of the window is: |animation_offset()|. |
| 101 canvas->TileImageInt(*dialog_left_, bounds.x(), animation_offset(), |
| 102 dialog_left_->width(), kAnimatingEdgeHeight); |
| 103 canvas->TileImageInt(*dialog_right_, |
| 104 bounds.width() - dialog_right_->width(), animation_offset(), |
| 105 dialog_right_->width(), kAnimatingEdgeHeight); |
| 106 } |
| 107 } |
| OLD | NEW |