blob: 1b35f0cdc12b1629bfd1deaeadf5936a2c073d74 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
// Copyright (c) 2011 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_BROWSER_UI_PANELS_PANEL_MANAGER_H_
#define CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_
#pragma once
#include <vector>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/panels/panel.h"
#include "ui/gfx/rect.h"
class Browser;
class Panel;
// This class manages a set of panels.
class PanelManager {
public:
// Returns a single instance.
static PanelManager* GetInstance();
~PanelManager();
// Called when the display is changed, i.e. work area is updated.
void OnDisplayChanged();
// Creates a panel and returns it. The panel might be queued for display
// later.
Panel* CreatePanel(Browser* browser);
void Remove(Panel* panel);
void RemoveAll();
// Drags the given panel.
void StartDragging(Panel* panel);
void Drag(int delta_x);
void EndDragging(bool cancelled);
// Should we bring up the titlebar, given the current mouse point?
bool ShouldBringUpTitleBarForAllMinimizedPanels(int mouse_x,
int mouse_y) const;
// Brings up or down the title-bar for all minimized panels.
void BringUpOrDownTitleBarForAllMinimizedPanels(bool bring_up);
int num_panels() const { return panels_.size(); }
private:
friend class PanelBrowserTest;
typedef std::vector<Panel*> Panels;
PanelManager();
// Applies the new work area. This is called by OnDisplayChanged and the test
// code.
void SetWorkArea(const gfx::Rect& work_area);
// Handles all the panels that're delayed to be removed.
void DelayedRemove();
// Does the remove. Called from Remove and DelayedRemove.
void DoRemove(Panel* panel);
// Rearranges the positions of the panels starting from the given iterator.
// This is called when the display space has been changed, i.e. working
// area being changed or a panel being closed.
void Rearrange(Panels::iterator iter_to_start);
// Computes the bounds for next panel.
// |allow_size_change| is used to indicate if the panel size can be changed to
// fall within the size constraint, e.g., when the panel is created.
// Returns true if computed bounds are within the displayable area.
bool ComputeBoundsForNextPanel(gfx::Rect* bounds, bool allow_size_change);
// Finds one panel to close so that we may have space for the new panel
// created by |extension|.
void FindAndClosePanelOnOverflow(const Extension* extension);
// Help functions to drag the given panel.
void DragLeft();
void DragRight();
Panels panels_;
// Stores the panels that are pending to remove. We want to delay the removal
// when we're in the process of the dragging.
Panels panels_pending_to_remove_;
// Current work area used in computing the panel bounds.
gfx::Rect work_area_;
// Used in computing the bounds of the next panel.
int max_width_;
int max_height_;
int min_x_;
int current_x_;
int bottom_edge_y_;
// Panel to drag.
size_t dragging_panel_index_;
// Original x coordinate of the panel to drag. This is used to get back to
// the original position when we cancel the dragging.
int dragging_panel_original_x_;
// Bounds of the panel to drag. It is first set to the original bounds when
// the dragging happens. Then it is updated to the position that will be set
// to when the dragging ends.
gfx::Rect dragging_panel_bounds_;
DISALLOW_COPY_AND_ASSIGN(PanelManager);
};
#endif // CHROME_BROWSER_UI_PANELS_PANEL_MANAGER_H_
|