Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: chrome/browser/ui/window_sizer.h

Issue 8549008: Extract MonitorInfoProvider from WindowSizer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 2 Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_H_ 5 #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_H_
6 #define CHROME_BROWSER_UI_WINDOW_SIZER_H_ 6 #define CHROME_BROWSER_UI_WINDOW_SIZER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector>
10
11 #include "base/basictypes.h" 9 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
13 #include "ui/gfx/rect.h" 11 #include "ui/gfx/rect.h"
14 12
15 class Browser; 13 class Browser;
14 class MonitorInfoProvider;
16 15
17 /////////////////////////////////////////////////////////////////////////////// 16 ///////////////////////////////////////////////////////////////////////////////
18 // WindowSizer 17 // WindowSizer
19 // 18 //
20 // A class that determines the best new size and position for a window to be 19 // A class that determines the best new size and position for a window to be
21 // shown at based several factors, including the position and size of the last 20 // shown at based several factors, including the position and size of the last
22 // window of the same type, the last saved bounds of the window from the 21 // window of the same type, the last saved bounds of the window from the
23 // previous session, and default system metrics if neither of the above two 22 // previous session, and default system metrics if neither of the above two
24 // conditions exist. The system has built-in providers for monitor metrics 23 // conditions exist. The system has built-in providers for monitor metrics
25 // and persistent storage (using preferences) but can be overrided with mocks 24 // and persistent storage (using preferences) but can be overrided with mocks
26 // for testing. 25 // for testing.
27 // 26 //
28 class WindowSizer { 27 class WindowSizer {
29 public: 28 public:
30 class MonitorInfoProvider;
31 class StateProvider; 29 class StateProvider;
32 30
33 // The WindowSizer assumes ownership of these objects. 31 // The WindowSizer assumes ownership of these objects.
34 WindowSizer(StateProvider* state_provider, 32 WindowSizer(StateProvider* state_provider,
35 MonitorInfoProvider* monitor_info_provider); 33 MonitorInfoProvider* monitor_info_provider);
36 virtual ~WindowSizer(); 34 virtual ~WindowSizer();
37 35
38 // Static factory methods to create default MonitorInfoProvider
39 // instances. The returned object is owned by the caller.
40 static MonitorInfoProvider* CreateDefaultMonitorInfoProvider();
41
42 // An interface implemented by an object that can retrieve information about
43 // the monitors on the system.
44 class MonitorInfoProvider {
45 public:
46 MonitorInfoProvider() {}
47 virtual ~MonitorInfoProvider() {}
48
49 // Returns the bounds of the work area of the primary monitor.
50 virtual gfx::Rect GetPrimaryMonitorWorkArea() const = 0;
51
52 // Returns the bounds of the primary monitor.
53 virtual gfx::Rect GetPrimaryMonitorBounds() const = 0;
54
55 // Returns the bounds of the work area of the monitor that most closely
56 // intersects the provided bounds.
57 virtual gfx::Rect GetMonitorWorkAreaMatching(
58 const gfx::Rect& match_rect) const = 0;
59
60 // Ensures number and coordinates of work areas are up-to-date. You must
61 // call this before calling either of the below functions, as work areas can
62 // change while the program is running.
63 virtual void UpdateWorkAreas() = 0;
64
65 // Returns the number of monitors on the system.
66 size_t GetMonitorCount() const {
67 return work_areas_.size();
68 }
69
70 // Returns the bounds of the work area of the monitor at the specified
71 // index.
72 gfx::Rect GetWorkAreaAt(size_t index) const {
73 return work_areas_[index];
74 }
75
76 protected:
77 std::vector<gfx::Rect> work_areas_;
78 };
79
80 // An interface implemented by an object that can retrieve state from either a 36 // An interface implemented by an object that can retrieve state from either a
81 // persistent store or an existing window. 37 // persistent store or an existing window.
82 class StateProvider { 38 class StateProvider {
83 public: 39 public:
84 virtual ~StateProvider() {} 40 virtual ~StateProvider() {}
85 41
86 // Retrieve the persisted bounds of the window. Returns true if there was 42 // Retrieve the persisted bounds of the window. Returns true if there was
87 // persisted data to retrieve state information, false otherwise. 43 // persisted data to retrieve state information, false otherwise.
88 virtual bool GetPersistentState(gfx::Rect* bounds, 44 virtual bool GetPersistentState(gfx::Rect* bounds,
89 gfx::Rect* work_area) const = 0; 45 gfx::Rect* work_area) const = 0;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 gfx::Rect* bounds) const; 114 gfx::Rect* bounds) const;
159 115
160 // Providers for persistent storage and monitor metrics. 116 // Providers for persistent storage and monitor metrics.
161 scoped_ptr<StateProvider> state_provider_; 117 scoped_ptr<StateProvider> state_provider_;
162 scoped_ptr<MonitorInfoProvider> monitor_info_provider_; 118 scoped_ptr<MonitorInfoProvider> monitor_info_provider_;
163 119
164 DISALLOW_COPY_AND_ASSIGN(WindowSizer); 120 DISALLOW_COPY_AND_ASSIGN(WindowSizer);
165 }; 121 };
166 122
167 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_H_ 123 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698