Chromium Code Reviews| 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/ui/tabs/tab_utils.h" | 5 #include "chrome/browser/ui/tabs/tab_utils.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 9 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 10 #include "chrome/browser/media/media_stream_capture_indicator.h" | 10 #include "chrome/browser/media/media_stream_capture_indicator.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/views/tabs/tab.h" | |
|
tdanderson
2015/02/06 20:34:33
I added this so that I can access the static metho
tdanderson
2015/02/10 18:52:17
No longer an issue since I've moved the new logic
| |
| 12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/animation/multi_animation.h" | 19 #include "ui/gfx/animation/multi_animation.h" |
| 19 | 20 |
| 20 namespace chrome { | 21 namespace chrome { |
| 21 | 22 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 base::TimeDelta::FromMilliseconds(kIndicatorFrameIntervalMs); | 74 base::TimeDelta::FromMilliseconds(kIndicatorFrameIntervalMs); |
| 74 scoped_ptr<TabRecordingIndicatorAnimation> animation( | 75 scoped_ptr<TabRecordingIndicatorAnimation> animation( |
| 75 new TabRecordingIndicatorAnimation(parts, interval)); | 76 new TabRecordingIndicatorAnimation(parts, interval)); |
| 76 animation->set_continuous(false); | 77 animation->set_continuous(false); |
| 77 return animation.Pass(); | 78 return animation.Pass(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 } // namespace | 81 } // namespace |
| 81 | 82 |
| 82 bool ShouldTabShowFavicon(int capacity, | 83 bool ShouldTabShowFavicon(int capacity, |
| 84 int width, | |
| 85 bool touch_used_last, | |
| 83 bool is_pinned_tab, | 86 bool is_pinned_tab, |
| 84 bool is_active_tab, | 87 bool is_active_tab, |
| 85 bool has_favicon, | 88 bool has_favicon, |
| 86 TabMediaState media_state) { | 89 TabMediaState media_state) { |
| 87 if (!has_favicon) | 90 if (!has_favicon) |
| 88 return false; | 91 return false; |
| 89 int required_capacity = 1; | 92 int required_capacity = 1; |
| 90 if (ShouldTabShowCloseButton(capacity, is_pinned_tab, is_active_tab)) | 93 if (ShouldTabShowCloseButton(capacity, |
| 94 width, | |
| 95 touch_used_last, | |
| 96 is_pinned_tab, | |
| 97 is_active_tab)) { | |
| 91 ++required_capacity; | 98 ++required_capacity; |
| 92 if (ShouldTabShowMediaIndicator( | 99 } |
| 93 capacity, is_pinned_tab, is_active_tab, has_favicon, media_state)) { | 100 if (ShouldTabShowMediaIndicator(capacity, |
| 101 width, | |
| 102 touch_used_last, | |
| 103 is_pinned_tab, | |
| 104 is_active_tab, | |
| 105 has_favicon, | |
| 106 media_state)) { | |
| 94 ++required_capacity; | 107 ++required_capacity; |
| 95 } | 108 } |
| 96 return capacity >= required_capacity; | 109 return capacity >= required_capacity; |
| 97 } | 110 } |
| 98 | 111 |
| 99 bool ShouldTabShowMediaIndicator(int capacity, | 112 bool ShouldTabShowMediaIndicator(int capacity, |
| 113 int width, | |
| 114 bool touch_used_last, | |
| 100 bool is_pinned_tab, | 115 bool is_pinned_tab, |
| 101 bool is_active_tab, | 116 bool is_active_tab, |
| 102 bool has_favicon, | 117 bool has_favicon, |
| 103 TabMediaState media_state) { | 118 TabMediaState media_state) { |
| 104 if (media_state == TAB_MEDIA_STATE_NONE) | 119 if (media_state == TAB_MEDIA_STATE_NONE) |
| 105 return false; | 120 return false; |
| 106 if (ShouldTabShowCloseButton(capacity, is_pinned_tab, is_active_tab)) | 121 if (ShouldTabShowCloseButton(capacity, |
| 122 width, | |
| 123 touch_used_last, | |
| 124 is_pinned_tab, | |
| 125 is_active_tab)) { | |
| 107 return capacity >= 2; | 126 return capacity >= 2; |
| 127 } | |
| 108 return capacity >= 1; | 128 return capacity >= 1; |
| 109 } | 129 } |
| 110 | 130 |
| 111 bool ShouldTabShowCloseButton(int capacity, | 131 bool ShouldTabShowCloseButton(int capacity, |
| 132 int width, | |
| 133 bool touch_used_last, | |
| 112 bool is_pinned_tab, | 134 bool is_pinned_tab, |
| 113 bool is_active_tab) { | 135 bool is_active_tab) { |
| 114 if (is_pinned_tab) | 136 if (is_pinned_tab) |
| 115 return false; | 137 return false; |
| 116 else if (is_active_tab) | 138 else if (is_active_tab) |
| 117 return true; | 139 return true; |
| 118 else | 140 |
| 119 return capacity >= 3; | 141 if (touch_used_last) { |
| 142 std::string switch_value = | |
| 143 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 144 switches::kTabCloseButtonsHiddenWithTouch); | |
| 145 if (switch_value == "always") | |
|
sky
2015/02/07 00:09:39
This code is basically saying if touch_used_last (
tdanderson
2015/02/10 18:52:17
Done.
| |
| 146 return false; | |
| 147 else if (switch_value == "narrow" && width < Tab::GetStandardSize().width()) | |
| 148 return false; | |
| 149 else if (switch_value == "stacked" && width <= Tab::GetTouchWidth()) | |
| 150 return false; | |
| 151 } | |
| 152 | |
| 153 return capacity >= 3; | |
| 120 } | 154 } |
| 121 | 155 |
| 122 bool IsPlayingAudio(content::WebContents* contents) { | 156 bool IsPlayingAudio(content::WebContents* contents) { |
| 123 return contents->WasRecentlyAudible(); | 157 return contents->WasRecentlyAudible(); |
| 124 } | 158 } |
| 125 | 159 |
| 126 TabMediaState GetTabMediaStateForContents(content::WebContents* contents) { | 160 TabMediaState GetTabMediaStateForContents(content::WebContents* contents) { |
| 127 if (!contents) | 161 if (!contents) |
| 128 return TAB_MEDIA_STATE_NONE; | 162 return TAB_MEDIA_STATE_NONE; |
| 129 | 163 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 const std::vector<int>& indices) { | 300 const std::vector<int>& indices) { |
| 267 for (std::vector<int>::const_iterator i = indices.begin(); i != indices.end(); | 301 for (std::vector<int>::const_iterator i = indices.begin(); i != indices.end(); |
| 268 ++i) { | 302 ++i) { |
| 269 if (!IsTabAudioMuted(tab_strip.GetWebContentsAt(*i))) | 303 if (!IsTabAudioMuted(tab_strip.GetWebContentsAt(*i))) |
| 270 return false; | 304 return false; |
| 271 } | 305 } |
| 272 return true; | 306 return true; |
| 273 } | 307 } |
| 274 | 308 |
| 275 } // namespace chrome | 309 } // namespace chrome |
| OLD | NEW |