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