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#ifndef CHROME_BROWSER_UI_VIEWS_TABS_DRAGGED_TAB_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_TABS_DRAGGED_TAB_VIEW_H_
7
8#include <vector>
9
10#include "build/build_config.h"
11#include "ui/gfx/point.h"
12#include "ui/gfx/rect.h"
13#include "ui/gfx/size.h"
14#include "ui/views/view.h"
15
16class NativeViewPhotobooth;
17
18class DraggedTabView : public views::View {
19 public:
20  // Creates a new DraggedTabView using |renderers| as the Views. DraggedTabView
21  // takes ownership of the views in |renderers| and |photobooth|.
22  DraggedTabView(const std::vector<views::View*>& renderers,
23                 const std::vector<gfx::Rect>& renderer_bounds,
24                 const gfx::Point& mouse_tab_offset,
25                 const gfx::Size& contents_size,
26                 NativeViewPhotobooth* photobooth);
27  virtual ~DraggedTabView();
28
29  // Moves the DraggedTabView to the appropriate location given the mouse
30  // pointer at |screen_point|.
31  void MoveTo(const gfx::Point& screen_point);
32
33  // Sets the offset of the mouse from the upper left corner of the tab.
34  void set_mouse_tab_offset(const gfx::Point& offset) {
35    mouse_tab_offset_ = offset;
36  }
37
38  // Notifies the DraggedTabView that it should update itself.
39  void Update();
40
41 private:
42  // Overridden from views::View:
43  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
44  virtual void Layout() OVERRIDE;
45  virtual gfx::Size GetPreferredSize() OVERRIDE;
46
47  // Paint the view, when it's not attached to any TabStrip.
48  void PaintDetachedView(gfx::Canvas* canvas);
49
50  // Paint the view, when "Show window contents while dragging" is disabled.
51  void PaintFocusRect(gfx::Canvas* canvas);
52
53  // Returns the preferred size of the container.
54  gfx::Size PreferredContainerSize();
55
56  // Utility for scaling a size by the current scaling factor.
57  int ScaleValue(int value);
58
59  // The window that contains the DraggedTabView.
60  scoped_ptr<views::Widget> container_;
61
62  // The renderer that paints the Tab shape.
63  std::vector<views::View*> renderers_;
64
65  // Bounds of the renderers.
66  std::vector<gfx::Rect> renderer_bounds_;
67
68  // True if "Show window contents while dragging" is enabled.
69  bool show_contents_on_drag_;
70
71  // The unscaled offset of the mouse from the top left of the dragged Tab.
72  // This is used to maintain an appropriate offset for the mouse pointer when
73  // dragging scaled and unscaled representations, and also to calculate the
74  // position of detached windows.
75  gfx::Point mouse_tab_offset_;
76
77  // The size of the tab renderer.
78  gfx::Size tab_size_;
79
80  // A handle to the DIB containing the current screenshot of the WebContents
81  // we are dragging.
82  scoped_ptr<NativeViewPhotobooth> photobooth_;
83
84  // Size of the WebContents being dragged.
85  gfx::Size contents_size_;
86
87  DISALLOW_COPY_AND_ASSIGN(DraggedTabView);
88};
89
90#endif  // CHROME_BROWSER_UI_VIEWS_TABS_DRAGGED_TAB_VIEW_H_
91