OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/chromeos/media/media_player.h" | 5 #include "chrome/browser/chromeos/media/media_player.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 11 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
12 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" | 12 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
17 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
18 #include "chrome/browser/ui/browser_tabstrip.h" | 18 #include "chrome/browser/ui/browser_tabstrip.h" |
19 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
20 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 #include "net/url_request/url_request_job.h" | 26 #include "net/url_request/url_request_job.h" |
27 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
28 | 28 |
29 using content::BrowserThread; | 29 using content::BrowserThread; |
30 using content::UserMetricsAction; | |
31 | 30 |
32 static const char* kMediaPlayerAppName = "mediaplayer"; | 31 static const char* kMediaPlayerAppName = "mediaplayer"; |
33 static const int kPopupRight = 20; | 32 static const int kPopupRight = 20; |
34 static const int kPopupBottom = 80; | 33 static const int kPopupBottom = 80; |
35 static const int kPopupWidth = 280; | 34 static const int kPopupWidth = 280; |
36 | 35 |
37 // Set the initial height to the minimum possible height. Keep the constants | 36 // Set the initial height to the minimum possible height. Keep the constants |
38 // in sync with chrome/browser/resources/file_manager/css/audio_player.css. | 37 // in sync with chrome/browser/resources/file_manager/css/audio_player.css. |
39 // SetWindowHeight will be called soon after the popup creation with the correct | 38 // SetWindowHeight will be called soon after the popup creation with the correct |
40 // height which will cause a nice slide-up animation. | 39 // height which will cause a nice slide-up animation. |
41 // TODO(kaznacheev): Remove kTitleHeight when MediaPlayer becomes chromeless. | 40 // TODO(kaznacheev): Remove kTitleHeight when MediaPlayer becomes chromeless. |
42 static const int kTitleHeight = 24; | 41 // kTitleHeight is an approximate value. May be different for touch-enabled UI. |
| 42 static const int kTitleHeight = 35; |
43 static const int kTrackHeight = 58; | 43 static const int kTrackHeight = 58; |
44 static const int kControlsHeight = 35; | 44 static const int kControlsHeight = 35; |
45 static const int kPopupHeight = kTitleHeight + kTrackHeight + kControlsHeight; | 45 static const int kPopupHeight = kTitleHeight + kTrackHeight + kControlsHeight; |
46 | 46 |
47 const MediaPlayer::UrlVector& MediaPlayer::GetPlaylist() const { | 47 const MediaPlayer::UrlVector& MediaPlayer::GetPlaylist() const { |
48 return current_playlist_; | 48 return current_playlist_; |
49 } | 49 } |
50 | 50 |
51 int MediaPlayer::GetPlaylistPosition() const { | 51 int MediaPlayer::GetPlaylistPosition() const { |
52 return current_position_; | 52 return current_position_; |
53 } | 53 } |
54 | 54 |
55 //////////////////////////////////////////////////////////////////////////////// | 55 //////////////////////////////////////////////////////////////////////////////// |
56 // | 56 // |
57 // Mediaplayer | 57 // Mediaplayer |
58 // | 58 // |
59 //////////////////////////////////////////////////////////////////////////////// | 59 //////////////////////////////////////////////////////////////////////////////// |
60 | 60 |
61 MediaPlayer::~MediaPlayer() { | 61 MediaPlayer::~MediaPlayer() { |
62 } | 62 } |
63 | 63 |
64 // static | 64 // static |
65 MediaPlayer* MediaPlayer::GetInstance() { | 65 MediaPlayer* MediaPlayer::GetInstance() { |
66 return Singleton<MediaPlayer>::get(); | 66 return Singleton<MediaPlayer>::get(); |
67 } | 67 } |
68 | 68 |
69 void MediaPlayer::SetWindowHeight(int content_height) { | 69 // The client knows how high the client part of the window should be but |
| 70 // cannot translate it to the window height (because the window title bar height |
| 71 // is unknown). Instead it passes the height difference which this method |
| 72 // applies to the window height. |
| 73 void MediaPlayer::AdjustWindowHeight(int height_diff) { |
70 Browser* browser = GetBrowser(); | 74 Browser* browser = GetBrowser(); |
71 if (browser != NULL) { | 75 if (browser != NULL) { |
72 int window_height = content_height + kTitleHeight; | |
73 gfx::Rect bounds = browser->window()->GetBounds(); | 76 gfx::Rect bounds = browser->window()->GetBounds(); |
| 77 int window_height = bounds.height() + height_diff; |
74 browser->window()->SetBounds(gfx::Rect( | 78 browser->window()->SetBounds(gfx::Rect( |
75 bounds.x(), | 79 bounds.x(), |
76 std::max(0, bounds.bottom() - window_height), | 80 std::max(0, bounds.bottom() - window_height), |
77 bounds.width(), | 81 bounds.width(), |
78 window_height)); | 82 window_height)); |
79 } | 83 } |
80 } | 84 } |
81 | 85 |
82 void MediaPlayer::CloseWindow() { | 86 void MediaPlayer::CloseWindow() { |
83 Browser* browser = GetBrowser(); | 87 Browser* browser = GetBrowser(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 Browser* browser = GetBrowser(); | 125 Browser* browser = GetBrowser(); |
122 if (!browser) { | 126 if (!browser) { |
123 const gfx::Size screen = | 127 const gfx::Size screen = |
124 ash::Shell::GetScreen()->GetPrimaryDisplay().size(); | 128 ash::Shell::GetScreen()->GetPrimaryDisplay().size(); |
125 const gfx::Rect bounds(screen.width() - kPopupRight - kPopupWidth, | 129 const gfx::Rect bounds(screen.width() - kPopupRight - kPopupWidth, |
126 screen.height() - kPopupBottom - kPopupHeight, | 130 screen.height() - kPopupBottom - kPopupHeight, |
127 kPopupWidth, | 131 kPopupWidth, |
128 kPopupHeight); | 132 kPopupHeight); |
129 | 133 |
130 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | 134 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
131 browser = new Browser( | 135 Browser::CreateParams params(Browser::TYPE_POPUP, profile); |
132 Browser::CreateParams::CreateForApp(Browser::TYPE_PANEL, | 136 params.app_name = kMediaPlayerAppName; |
133 kMediaPlayerAppName, | 137 params.initial_bounds = bounds; |
134 bounds, | 138 browser = new Browser(params); |
135 profile)); | |
136 | 139 |
137 chrome::AddSelectedTabWithURL(browser, GetMediaPlayerUrl(), | 140 chrome::AddSelectedTabWithURL(browser, GetMediaPlayerUrl(), |
138 content::PAGE_TRANSITION_LINK); | 141 content::PAGE_TRANSITION_LINK); |
139 } | 142 } |
140 browser->window()->Show(); | 143 browser->window()->Show(); |
141 } | 144 } |
142 | 145 |
143 GURL MediaPlayer::GetMediaPlayerUrl() { | 146 GURL MediaPlayer::GetMediaPlayerUrl() { |
144 return file_manager_util::GetMediaPlayerUrl(); | 147 return file_manager_util::GetMediaPlayerUrl(); |
145 } | 148 } |
(...skipping 11 matching lines...) Expand all Loading... |
157 if (base_url == GetMediaPlayerUrl()) | 160 if (base_url == GetMediaPlayerUrl()) |
158 return browser; | 161 return browser; |
159 } | 162 } |
160 } | 163 } |
161 return NULL; | 164 return NULL; |
162 } | 165 } |
163 | 166 |
164 MediaPlayer::MediaPlayer() | 167 MediaPlayer::MediaPlayer() |
165 : current_position_(0) { | 168 : current_position_(0) { |
166 }; | 169 }; |
OLD | NEW |