browser_root_view.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
1// Copyright (c) 2012 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_FRAME_BROWSER_ROOT_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_ROOT_VIEW_H_
7
8#include "ui/views/widget/root_view.h"
9
10class BrowserView;
11class TabStrip;
12
13namespace ui {
14class OSExchangeData;
15}
16
17// RootView implementation used by BrowserFrame. This forwards drop events to
18// the TabStrip. Visually the tabstrip extends to the top of the frame, but in
19// actually it doesn't. The tabstrip is only as high as a tab. To enable
20// dropping above the tabstrip BrowserRootView forwards drop events to the
21// TabStrip.
22class BrowserRootView : public views::internal::RootView {
23 public:
24  // Internal class name.
25  static const char kViewClassName[];
26
27  // You must call set_tabstrip before this class will accept drops.
28  BrowserRootView(BrowserView* browser_view, views::Widget* widget);
29
30  // Overridden from views::View:
31  virtual bool GetDropFormats(
32      int* formats,
33      std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
34  virtual bool AreDropTypesRequired() OVERRIDE;
35  virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE;
36  virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE;
37  virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
38  virtual void OnDragExited() OVERRIDE;
39  virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
40  virtual const char* GetClassName() const OVERRIDE;
41
42 private:
43  // Returns true if the event should be forwarded to the tabstrip.
44  bool ShouldForwardToTabStrip(const ui::DropTargetEvent& event);
45
46  // Converts the event from the hosts coordinate system to the tabstrips
47  // coordinate system.
48  ui::DropTargetEvent* MapEventToTabStrip(
49      const ui::DropTargetEvent& event,
50      const ui::OSExchangeData& data);
51
52  inline TabStrip* tabstrip() const;
53
54  // Returns true if |data| has string contents and the user can "paste and go".
55  // If |url| is non-NULL and the user can "paste and go", |url| is set to the
56  // desired destination.
57  bool GetPasteAndGoURL(const ui::OSExchangeData& data, GURL* url);
58
59  // The BrowserView.
60  BrowserView* browser_view_;
61
62  // If true, drag and drop events are being forwarded to the tab strip.
63  // This is used to determine when to send OnDragEntered and OnDragExited
64  // to the tab strip.
65  bool forwarding_to_tab_strip_;
66
67  DISALLOW_COPY_AND_ASSIGN(BrowserRootView);
68};
69
70#endif  // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_ROOT_VIEW_H_
71