summaryrefslogtreecommitdiffstats
path: root/chrome/views/single_split_view.h
blob: 53f64a8de589f8540cf1ecad5cc86defa9dd2cc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_VIEWS_SINGLE_SPLIT_VIEW_H_
#define CHROME_VIEWS_SINGLE_SPLIT_VIEW_H_

#include "chrome/views/view.h"

namespace views {

// SingleSplitView lays out two views horizontally. A splitter exists between
// the two views that the user can drag around to resize the views.
class SingleSplitView : public views::View {
 public:
  SingleSplitView(View* leading, View* trailing);

  virtual void Layout();

  // SingleSplitView's preferred size is the sum of the preferred widths
  // and the max of the heights.
  virtual gfx::Size GetPreferredSize();

  // Overriden to return a resize cursor when over the divider.
  virtual HCURSOR GetCursorForPoint(Event::EventType event_type, int x, int y);

  void set_divider_x(int divider_x) { divider_x_ = divider_x; }
  int divider_x() { return divider_x_; }

 protected:
  virtual bool OnMousePressed(const MouseEvent& event);
  virtual bool OnMouseDragged(const MouseEvent& event);
  virtual void OnMouseReleased(const MouseEvent& event, bool canceled);

 private:
  // Returns true if |x| is over the divider.
  bool IsPointInDivider(int x);

  // Used to track drag info.
  struct DragInfo {
    // The initial coordinate of the mouse when the user started the drag.
    int initial_mouse_x;
    // The initial position of the divider when the user started the drag.
    int initial_divider_x;
  };

  DragInfo drag_info_;

  // Position of the divider.
  int divider_x_;

  DISALLOW_COPY_AND_ASSIGN(SingleSplitView);
};

}  // namespace views

#endif  // CHROME_VIEWS_SINGLE_SPLIT_VIEW_H_