Commit 8f0ec23f authored by Tibor Goldschwendt's avatar Tibor Goldschwendt Committed by Commit Bot

[vr] Add ability to close tab in tabs view

Adds a button to close tab and plumbing to send the close request to
Java.

Bug: 838937
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr
Change-Id: I45d6d8c3c66674bc472a17335a6e02195f8a23b8
Reviewed-on: https://chromium-review.googlesource.com/1050794
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557964}
parent 1c4d0048
...@@ -50,7 +50,6 @@ import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; ...@@ -50,7 +50,6 @@ import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver; import org.chromium.chrome.browser.tabmodel.TabModelSelectorObserver;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
import org.chromium.chrome.browser.tabmodel.TabModelUtils; import org.chromium.chrome.browser.tabmodel.TabModelUtils;
import org.chromium.chrome.browser.vr_shell.keyboard.VrInputMethodManagerWrapper; import org.chromium.chrome.browser.vr_shell.keyboard.VrInputMethodManagerWrapper;
...@@ -88,7 +87,6 @@ public class VrShellImpl ...@@ -88,7 +87,6 @@ public class VrShellImpl
private final boolean mVrBrowsingEnabled; private final boolean mVrBrowsingEnabled;
private TabModelSelectorTabObserver mTabModelSelectorTabObserver; private TabModelSelectorTabObserver mTabModelSelectorTabObserver;
private TabModelSelectorTabModelObserver mTabModelSelectorTabModelObserver;
private long mNativeVrShell; private long mNativeVrShell;
...@@ -378,7 +376,6 @@ public class VrShellImpl ...@@ -378,7 +376,6 @@ public class VrShellImpl
createTabList(); createTabList();
mActivity.getTabModelSelector().addObserver(mTabModelSelectorObserver); mActivity.getTabModelSelector().addObserver(mTabModelSelectorObserver);
attachTabModelSelectorTabObserver(); attachTabModelSelectorTabObserver();
attachTabModelSelectorTabModelObserver();
updateHistoryButtonsVisibility(); updateHistoryButtonsVisibility();
mPresentationView.setOnTouchListener(mTouchListener); mPresentationView.setOnTouchListener(mTouchListener);
...@@ -717,7 +714,6 @@ public class VrShellImpl ...@@ -717,7 +714,6 @@ public class VrShellImpl
} }
mTabModelSelector.removeObserver(mTabModelSelectorObserver); mTabModelSelector.removeObserver(mTabModelSelectorObserver);
mTabModelSelectorTabObserver.destroy(); mTabModelSelectorTabObserver.destroy();
mTabModelSelectorTabModelObserver.destroy();
if (mTab != null) { if (mTab != null) {
mTab.removeObserver(mTabObserver); mTab.removeObserver(mTabObserver);
restoreTabFromVR(); restoreTabFromVR();
...@@ -944,18 +940,6 @@ public class VrShellImpl ...@@ -944,18 +940,6 @@ public class VrShellImpl
}; };
} }
/** Creates and attaches a TabModelSelectorTabModelObserver to the tab model selector. */
private void attachTabModelSelectorTabModelObserver() {
assert mTabModelSelectorTabModelObserver == null;
mTabModelSelectorTabModelObserver =
new TabModelSelectorTabModelObserver(mTabModelSelector) {
@Override
public void didSelectTab(Tab tab, TabSelectionType type, int lastId) {
nativeOnTabSelected(mNativeVrShell, tab.isIncognito(), tab.getId());
}
};
}
@CalledByNative @CalledByNative
public boolean hasDaydreamSupport() { public boolean hasDaydreamSupport() {
return mDelegate.hasDaydreamSupport(); return mDelegate.hasDaydreamSupport();
...@@ -1063,6 +1047,11 @@ public class VrShellImpl ...@@ -1063,6 +1047,11 @@ public class VrShellImpl
mActivity.onMenuOrKeyboardAction(R.id.preferences_id, true); mActivity.onMenuOrKeyboardAction(R.id.preferences_id, true);
} }
@CalledByNative
public void closeTab(int id, boolean incognito) {
TabModelUtils.closeTabById(mTabModelSelector.getModel(incognito), id);
}
@CalledByNative @CalledByNative
public void closeAllTabs() { public void closeAllTabs() {
mTabModelSelector.closeAllTabs(); mTabModelSelector.closeAllTabs();
...@@ -1262,7 +1251,6 @@ public class VrShellImpl ...@@ -1262,7 +1251,6 @@ public class VrShellImpl
private native void nativeOnTabUpdated(long nativeVrShell, boolean incognito, int id, private native void nativeOnTabUpdated(long nativeVrShell, boolean incognito, int id,
String title); String title);
private native void nativeOnTabRemoved(long nativeVrShell, boolean incognito, int id); private native void nativeOnTabRemoved(long nativeVrShell, boolean incognito, int id);
private native void nativeOnTabSelected(long nativeVrShell, boolean incognito, int id);
private native void nativeCloseAlertDialog(long nativeVrShell); private native void nativeCloseAlertDialog(long nativeVrShell);
private native void nativeSetAlertDialog(long nativeVrShell, float width, float height); private native void nativeSetAlertDialog(long nativeVrShell, float width, float height);
private native void nativeSetDialogBufferSize(long nativeVrShell, float width, float height); private native void nativeSetDialogBufferSize(long nativeVrShell, float width, float height);
......
...@@ -292,6 +292,13 @@ void VrGLThread::OpenSettings() { ...@@ -292,6 +292,13 @@ void VrGLThread::OpenSettings() {
FROM_HERE, base::BindOnce(&VrShell::OpenSettings, weak_vr_shell_)); FROM_HERE, base::BindOnce(&VrShell::OpenSettings, weak_vr_shell_));
} }
void VrGLThread::CloseTab(int id, bool incognito) {
DCHECK(OnGlThread());
main_thread_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&VrShell::CloseTab, weak_vr_shell_, id, incognito));
}
void VrGLThread::CloseAllTabs() { void VrGLThread::CloseAllTabs() {
DCHECK(OnGlThread()); DCHECK(OnGlThread());
main_thread_task_runner_->PostTask( main_thread_task_runner_->PostTask(
...@@ -546,13 +553,6 @@ void VrGLThread::RemoveAllTabs() { ...@@ -546,13 +553,6 @@ void VrGLThread::RemoveAllTabs() {
base::BindOnce(&BrowserUiInterface::RemoveAllTabs, weak_browser_ui_)); base::BindOnce(&BrowserUiInterface::RemoveAllTabs, weak_browser_ui_));
} }
void VrGLThread::OnTabSelected(int id, bool incognito) {
DCHECK(OnMainThread());
task_runner()->PostTask(FROM_HERE,
base::BindOnce(&BrowserUiInterface::OnTabSelected,
weak_browser_ui_, id, incognito));
}
void VrGLThread::ReportUiActivityResultForTesting( void VrGLThread::ReportUiActivityResultForTesting(
const VrUiTestActivityResult& result) { const VrUiTestActivityResult& result) {
DCHECK(OnGlThread()); DCHECK(OnGlThread());
......
...@@ -94,6 +94,7 @@ class VrGLThread : public base::android::JavaHandlerThread, ...@@ -94,6 +94,7 @@ class VrGLThread : public base::android::JavaHandlerThread,
void OpenDownloads() override; void OpenDownloads() override;
void OpenShare() override; void OpenShare() override;
void OpenSettings() override; void OpenSettings() override;
void CloseTab(int id, bool incognito) override;
void CloseAllTabs() override; void CloseAllTabs() override;
void CloseAllIncognitoTabs() override; void CloseAllIncognitoTabs() override;
void OpenFeedback() override; void OpenFeedback() override;
...@@ -139,7 +140,6 @@ class VrGLThread : public base::android::JavaHandlerThread, ...@@ -139,7 +140,6 @@ class VrGLThread : public base::android::JavaHandlerThread,
const base::string16& title) override; const base::string16& title) override;
void RemoveTab(int id, bool incognito) override; void RemoveTab(int id, bool incognito) override;
void RemoveAllTabs() override; void RemoveAllTabs() override;
void OnTabSelected(int id, bool incognito) override;
void ReportUiActivityResultForTesting( void ReportUiActivityResultForTesting(
const VrUiTestActivityResult& result) override; const VrUiTestActivityResult& result) override;
......
...@@ -408,6 +408,11 @@ void VrShell::OpenSettings() { ...@@ -408,6 +408,11 @@ void VrShell::OpenSettings() {
Java_VrShellImpl_openSettings(env, j_vr_shell_); Java_VrShellImpl_openSettings(env, j_vr_shell_);
} }
void VrShell::CloseTab(int id, bool incognito) {
JNIEnv* env = base::android::AttachCurrentThread();
Java_VrShellImpl_closeTab(env, j_vr_shell_, id, incognito);
}
void VrShell::CloseAllTabs() { void VrShell::CloseAllTabs() {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
Java_VrShellImpl_closeAllTabs(env, j_vr_shell_); Java_VrShellImpl_closeAllTabs(env, j_vr_shell_);
...@@ -630,13 +635,6 @@ void VrShell::OnTabRemoved(JNIEnv* env, ...@@ -630,13 +635,6 @@ void VrShell::OnTabRemoved(JNIEnv* env,
ui_->RemoveTab(id, incognito); ui_->RemoveTab(id, incognito);
} }
void VrShell::OnTabSelected(JNIEnv* env,
const JavaParamRef<jobject>& obj,
jboolean incognito,
jint id) {
ui_->OnTabSelected(id, incognito);
}
void VrShell::SetAlertDialog(JNIEnv* env, void VrShell::SetAlertDialog(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
float width, float width,
......
...@@ -129,10 +129,6 @@ class VrShell : device::GvrGamepadDataProvider, ...@@ -129,10 +129,6 @@ class VrShell : device::GvrGamepadDataProvider,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
jboolean incognito, jboolean incognito,
jint id); jint id);
void OnTabSelected(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
jboolean incognito,
jint id);
void OnContentPaused(bool paused); void OnContentPaused(bool paused);
void Navigate(GURL url, NavigationMethod method); void Navigate(GURL url, NavigationMethod method);
void NavigateBack(); void NavigateBack();
...@@ -146,6 +142,7 @@ class VrShell : device::GvrGamepadDataProvider, ...@@ -146,6 +142,7 @@ class VrShell : device::GvrGamepadDataProvider,
void OpenDownloads(); void OpenDownloads();
void OpenShare(); void OpenShare();
void OpenSettings(); void OpenSettings();
void CloseTab(int id, bool incognito);
void CloseAllTabs(); void CloseAllTabs();
void CloseAllIncognitoTabs(); void CloseAllIncognitoTabs();
void OpenFeedback(); void OpenFeedback();
......
...@@ -56,7 +56,6 @@ class BrowserUiInterface { ...@@ -56,7 +56,6 @@ class BrowserUiInterface {
const base::string16& title) = 0; const base::string16& title) = 0;
virtual void RemoveTab(int id, bool incognito) = 0; virtual void RemoveTab(int id, bool incognito) = 0;
virtual void RemoveAllTabs() = 0; virtual void RemoveAllTabs() = 0;
virtual void OnTabSelected(int id, bool incognito) = 0;
}; };
} // namespace vr } // namespace vr
......
...@@ -138,9 +138,11 @@ void Shadow::Render(UiElementRenderer* renderer, ...@@ -138,9 +138,11 @@ void Shadow::Render(UiElementRenderer* renderer,
} }
void Shadow::LayOutChildren() { void Shadow::LayOutChildren() {
DCHECK(!children().empty()); DCHECK(shadow_caster_ || !children().empty());
UiElement* shadow_caster =
shadow_caster_ ? shadow_caster_ : children().back().get();
gfx::Point3F p; gfx::Point3F p;
children().back()->LocalTransform().TransformPoint(&p); shadow_caster->LocalTransform().TransformPoint(&p);
DCHECK_GE(kMaximumChildDepth, p.z()); DCHECK_GE(kMaximumChildDepth, p.z());
depth_ = base::ClampToRange(p.z() / kMaximumChildDepth, 0.0f, 1.0f); depth_ = base::ClampToRange(p.z() / kMaximumChildDepth, 0.0f, 1.0f);
// This is an arbitrary function that quickly accelerates from 0 toward 1. // This is an arbitrary function that quickly accelerates from 0 toward 1.
...@@ -148,8 +150,8 @@ void Shadow::LayOutChildren() { ...@@ -148,8 +150,8 @@ void Shadow::LayOutChildren() {
kXMaxShadowGradientFactor), kXMaxShadowGradientFactor),
gfx::Tween::FloatValueBetween(depth_, kYMinShadowGradientFactor, gfx::Tween::FloatValueBetween(depth_, kYMinShadowGradientFactor,
kYMaxShadowGradientFactor)); kYMaxShadowGradientFactor));
if (children().size() == 1u) if (shadow_caster_ || children().size() == 1u)
set_corner_radius(children().back()->corner_radii().MaxRadius()); set_corner_radius(shadow_caster->corner_radii().MaxRadius());
} }
Shadow::Renderer::Renderer() Shadow::Renderer::Renderer()
......
...@@ -14,6 +14,8 @@ namespace vr { ...@@ -14,6 +14,8 @@ namespace vr {
// A shadow is meant to be the ancestor of elements to which a shadow is to be // A shadow is meant to be the ancestor of elements to which a shadow is to be
// applied. The shadow is applied across its padding. // applied. The shadow is applied across its padding.
// By default the direct child is used as the shadow caster. This behavior can
// be changed by manually setting a shadow caster.
class Shadow : public UiElement { class Shadow : public UiElement {
public: public:
Shadow(); Shadow();
...@@ -24,6 +26,9 @@ class Shadow : public UiElement { ...@@ -24,6 +26,9 @@ class Shadow : public UiElement {
void LayOutChildren() override; void LayOutChildren() override;
void set_intensity(float intensity) { intensity_ = intensity; } void set_intensity(float intensity) { intensity_ = intensity; }
void set_shadow_caster(UiElement* shadow_caster) {
shadow_caster_ = shadow_caster;
}
class Renderer : public BaseQuadRenderer { class Renderer : public BaseQuadRenderer {
public: public:
...@@ -55,6 +60,7 @@ class Shadow : public UiElement { ...@@ -55,6 +60,7 @@ class Shadow : public UiElement {
private: private:
float depth_; float depth_;
float intensity_ = 1.0f; float intensity_ = 1.0f;
UiElement* shadow_caster_ = nullptr;
gfx::SizeF contributed_size_; gfx::SizeF contributed_size_;
DISALLOW_COPY_AND_ASSIGN(Shadow); DISALLOW_COPY_AND_ASSIGN(Shadow);
......
...@@ -45,6 +45,8 @@ static const char* g_ui_element_type_strings[] = { ...@@ -45,6 +45,8 @@ static const char* g_ui_element_type_strings[] = {
"kTypeOverflowMenuItem", "kTypeOverflowMenuItem",
"kTypeTooltip", "kTypeTooltip",
"kTypeLabel", "kTypeLabel",
"kTypeTabItem",
"kTypeTabItemRemoveButton",
}; };
static_assert( static_assert(
......
...@@ -45,6 +45,8 @@ enum UiElementType { ...@@ -45,6 +45,8 @@ enum UiElementType {
kTypeOverflowMenuItem, kTypeOverflowMenuItem,
kTypeTooltip, kTypeTooltip,
kTypeLabel, kTypeLabel,
kTypeTabItem,
kTypeTabItemRemoveButton,
// This must be last. // This must be last.
kNumUiElementTypes, kNumUiElementTypes,
......
...@@ -46,7 +46,6 @@ class MockBrowserUiInterface : public BrowserUiInterface { ...@@ -46,7 +46,6 @@ class MockBrowserUiInterface : public BrowserUiInterface {
void(int id, bool incognito, const base::string16& title)); void(int id, bool incognito, const base::string16& title));
MOCK_METHOD2(RemoveTab, void(int id, bool incognito)); MOCK_METHOD2(RemoveTab, void(int id, bool incognito));
MOCK_METHOD0(RemoveAllTabs, void()); MOCK_METHOD0(RemoveAllTabs, void());
MOCK_METHOD2(OnTabSelected, void(int id, bool incognito));
private: private:
DISALLOW_COPY_AND_ASSIGN(MockBrowserUiInterface); DISALLOW_COPY_AND_ASSIGN(MockBrowserUiInterface);
......
...@@ -30,6 +30,7 @@ class MockUiBrowserInterface : public UiBrowserInterface { ...@@ -30,6 +30,7 @@ class MockUiBrowserInterface : public UiBrowserInterface {
MOCK_METHOD0(OpenDownloads, void()); MOCK_METHOD0(OpenDownloads, void());
MOCK_METHOD0(OpenShare, void()); MOCK_METHOD0(OpenShare, void());
MOCK_METHOD0(OpenSettings, void()); MOCK_METHOD0(OpenSettings, void());
MOCK_METHOD2(CloseTab, void(int id, bool incognito));
MOCK_METHOD0(CloseAllTabs, void()); MOCK_METHOD0(CloseAllTabs, void());
MOCK_METHOD0(CloseAllIncognitoTabs, void()); MOCK_METHOD0(CloseAllIncognitoTabs, void());
MOCK_METHOD0(OpenFeedback, void()); MOCK_METHOD0(OpenFeedback, void());
......
...@@ -580,9 +580,7 @@ void VrTestContext::OpenNewTab(bool incognito) { ...@@ -580,9 +580,7 @@ void VrTestContext::OpenNewTab(bool incognito) {
ui_->AddOrUpdateTab(tab_id_++, incognito, base::UTF8ToUTF16("test")); ui_->AddOrUpdateTab(tab_id_++, incognito, base::UTF8ToUTF16("test"));
} }
void VrTestContext::SelectTab(int id, bool incognito) { void VrTestContext::SelectTab(int id, bool incognito) {}
ui_->OnTabSelected(id, incognito);
}
void VrTestContext::OpenBookmarks() {} void VrTestContext::OpenBookmarks() {}
void VrTestContext::OpenRecentTabs() {} void VrTestContext::OpenRecentTabs() {}
...@@ -591,6 +589,10 @@ void VrTestContext::OpenDownloads() {} ...@@ -591,6 +589,10 @@ void VrTestContext::OpenDownloads() {}
void VrTestContext::OpenShare() {} void VrTestContext::OpenShare() {}
void VrTestContext::OpenSettings() {} void VrTestContext::OpenSettings() {}
void VrTestContext::CloseTab(int id, bool incognito) {
ui_->RemoveTab(id, incognito);
}
void VrTestContext::CloseAllTabs() { void VrTestContext::CloseAllTabs() {
incognito_ = false; incognito_ = false;
ui_->SetIncognito(false); ui_->SetIncognito(false);
......
...@@ -55,6 +55,7 @@ class VrTestContext : public vr::UiBrowserInterface { ...@@ -55,6 +55,7 @@ class VrTestContext : public vr::UiBrowserInterface {
void OpenDownloads() override; void OpenDownloads() override;
void OpenShare() override; void OpenShare() override;
void OpenSettings() override; void OpenSettings() override;
void CloseTab(int id, bool incognito) override;
void CloseAllTabs() override; void CloseAllTabs() override;
void CloseAllIncognitoTabs() override; void CloseAllIncognitoTabs() override;
void OpenFeedback() override; void OpenFeedback() override;
......
...@@ -268,10 +268,6 @@ void Ui::RemoveAllTabs() { ...@@ -268,10 +268,6 @@ void Ui::RemoveAllTabs() {
model_->incognito_tabs.clear(); model_->incognito_tabs.clear();
} }
void Ui::OnTabSelected(int id, bool incognito) {
model_->pop_mode(kModeTabsView);
}
bool Ui::CanSendWebVrVSync() { bool Ui::CanSendWebVrVSync() {
return model_->web_vr_enabled() && return model_->web_vr_enabled() &&
!model_->web_vr.awaiting_min_splash_screen_duration() && !model_->web_vr.awaiting_min_splash_screen_duration() &&
......
...@@ -115,7 +115,6 @@ class Ui : public BrowserUiInterface, public KeyboardUiInterface { ...@@ -115,7 +115,6 @@ class Ui : public BrowserUiInterface, public KeyboardUiInterface {
const base::string16& title) override; const base::string16& title) override;
void RemoveTab(int id, bool incognito) override; void RemoveTab(int id, bool incognito) override;
void RemoveAllTabs() override; void RemoveAllTabs() override;
void OnTabSelected(int id, bool incognito) override;
// TODO(ymalik): We expose this to stop sending VSync to the WebVR page until // TODO(ymalik): We expose this to stop sending VSync to the WebVR page until
// the splash screen has been visible for its minimum duration. The visibility // the splash screen has been visible for its minimum duration. The visibility
......
...@@ -40,6 +40,7 @@ class UiBrowserInterface { ...@@ -40,6 +40,7 @@ class UiBrowserInterface {
virtual void OpenDownloads() = 0; virtual void OpenDownloads() = 0;
virtual void OpenShare() = 0; virtual void OpenShare() = 0;
virtual void OpenSettings() = 0; virtual void OpenSettings() = 0;
virtual void CloseTab(int id, bool incognito) = 0;
virtual void CloseAllTabs() = 0; virtual void CloseAllTabs() = 0;
virtual void CloseAllIncognitoTabs() = 0; virtual void CloseAllIncognitoTabs() = 0;
virtual void OpenFeedback() = 0; virtual void OpenFeedback() = 0;
......
...@@ -302,6 +302,10 @@ static constexpr float kTabsViewVerticalOffsetDMM = -0.1f; ...@@ -302,6 +302,10 @@ static constexpr float kTabsViewVerticalOffsetDMM = -0.1f;
static constexpr float kTabsViewModeButtonWidthDMM = 0.25f; static constexpr float kTabsViewModeButtonWidthDMM = 0.25f;
static constexpr float kTabsViewModeButtonHeightDMM = 0.075f; static constexpr float kTabsViewModeButtonHeightDMM = 0.075f;
static constexpr float kTabsViewModeButtonTextSizeDMM = 0.03f; static constexpr float kTabsViewModeButtonTextSizeDMM = 0.03f;
static constexpr float kTabsViewRemoveButtonShadowIntensity = 0.4f;
static constexpr float kTabsViewRemoveButtonDepthOffsetDMM = 0.02f;
static constexpr float kTabsViewRemoveButtonSizeDMM = 0.05f;
static constexpr float kTabsViewRemoveButtonHoverOffsetDMM = 0.015f;
} // namespace vr } // namespace vr
......
...@@ -274,7 +274,7 @@ void OnSuggestionModelRemoved(UiScene* scene, SuggestionBinding* binding) { ...@@ -274,7 +274,7 @@ void OnSuggestionModelRemoved(UiScene* scene, SuggestionBinding* binding) {
scene->RemoveUiElement(binding->view()->id()); scene->RemoveUiElement(binding->view()->id());
} }
typedef VectorBinding<TabModel, Rect> TabSetBinding; typedef VectorBinding<TabModel, UiElement> TabSetBinding;
typedef typename TabSetBinding::ElementBinding TabBinding; typedef typename TabSetBinding::ElementBinding TabBinding;
void OnTabModelAdded(UiScene* scene, void OnTabModelAdded(UiScene* scene,
...@@ -284,7 +284,7 @@ void OnTabModelAdded(UiScene* scene, ...@@ -284,7 +284,7 @@ void OnTabModelAdded(UiScene* scene,
AudioDelegate* audio_delegate, AudioDelegate* audio_delegate,
UiBrowserInterface* browser, UiBrowserInterface* browser,
TabBinding* element_binding) { TabBinding* element_binding) {
auto item = Create<Button>(kNone, kPhaseForeground, base::RepeatingClosure(), auto item = Create<Button>(kNone, kPhaseForeground, base::DoNothing(),
audio_delegate); audio_delegate);
item->SetButtonColors( item->SetButtonColors(
ColorScheme::GetColorScheme(incognito ? ColorScheme::kModeIncognito ColorScheme::GetColorScheme(incognito ? ColorScheme::kModeIncognito
...@@ -293,6 +293,8 @@ void OnTabModelAdded(UiScene* scene, ...@@ -293,6 +293,8 @@ void OnTabModelAdded(UiScene* scene,
item->SetSize(kTabItemWidthDMM, kTabItemHeightDMM); item->SetSize(kTabItemWidthDMM, kTabItemHeightDMM);
item->SetTransitionedProperties({OPACITY}); item->SetTransitionedProperties({OPACITY});
item->set_corner_radius(kTabItemCornerRadiusDMM); item->set_corner_radius(kTabItemCornerRadiusDMM);
item->set_hover_offset(0.0f);
item->SetType(kTypeTabItem);
item->AddBinding(std::make_unique<Binding<PagedGridLayout::PageState>>( item->AddBinding(std::make_unique<Binding<PagedGridLayout::PageState>>(
VR_BIND_LAMBDA( VR_BIND_LAMBDA(
[](PagedGridLayout* paged_layout, UiElement* item) { [](PagedGridLayout* paged_layout, UiElement* item) {
...@@ -324,15 +326,21 @@ void OnTabModelAdded(UiScene* scene, ...@@ -324,15 +326,21 @@ void OnTabModelAdded(UiScene* scene,
}, },
base::Unretained(element_binding)), base::Unretained(element_binding)),
VR_BIND_LAMBDA( VR_BIND_LAMBDA(
[](Button* item, UiBrowserInterface* browser, bool incognito, [](TabBinding* element_binding, UiBrowserInterface* browser,
const int& id) { Model* model, bool incognito, const int& id) {
item->set_click_handler(base::BindRepeating( static_cast<Button*>(
[](UiBrowserInterface* browser, int id, bool incognito) { element_binding->view()->GetDescendantByType(kTypeTabItem))
browser->SelectTab(id, incognito); ->set_click_handler(base::BindRepeating(
}, [](UiBrowserInterface* browser, Model* model, int id,
base::Unretained(browser), id, incognito)); bool incognito) {
browser->SelectTab(id, incognito);
model->pop_mode(kModeTabsView);
},
base::Unretained(browser), base::Unretained(model), id,
incognito));
}, },
base::Unretained(item.get()), base::Unretained(browser), incognito))); base::Unretained(element_binding), base::Unretained(browser),
base::Unretained(model), incognito)));
// TODO(crbug.com/838937): This is just a placeholder text. Replace with // TODO(crbug.com/838937): This is just a placeholder text. Replace with
// proper tab item. // proper tab item.
...@@ -349,6 +357,61 @@ void OnTabModelAdded(UiScene* scene, ...@@ -349,6 +357,61 @@ void OnTabModelAdded(UiScene* scene,
.tab_item_text); .tab_item_text);
item->background()->AddChild(std::move(text)); item->background()->AddChild(std::move(text));
auto shadow = Create<Shadow>(kNone, kPhaseForeground);
shadow->set_x_anchoring(RIGHT);
shadow->set_y_anchoring(TOP);
shadow->set_intensity(kTabsViewRemoveButtonShadowIntensity);
shadow->SetTransitionedProperties({OPACITY});
auto remove_button =
Create<DiscButton>(kNone, kPhaseForeground, base::DoNothing(),
vector_icons::kCloseRoundedIcon, nullptr);
remove_button->SetTranslate(0, 0, kTabsViewRemoveButtonDepthOffsetDMM);
remove_button->SetSize(kTabsViewRemoveButtonSizeDMM,
kTabsViewRemoveButtonSizeDMM);
remove_button->SetType(kTypeTabItemRemoveButton);
remove_button->set_hover_offset(kTabsViewRemoveButtonHoverOffsetDMM);
Sounds sounds;
sounds.hover_enter = kSoundButtonHover;
sounds.button_down = kSoundButtonClick;
remove_button->SetSounds(sounds, audio_delegate);
VR_BIND_BUTTON_COLORS(model, remove_button.get(),
&ColorScheme::disc_button_colors,
&DiscButton::SetButtonColors);
element_binding->bindings().push_back(std::make_unique<Binding<int>>(
VR_BIND_LAMBDA(
[](TabBinding* element_binding) {
return element_binding->model()->id;
},
base::Unretained(element_binding)),
VR_BIND_LAMBDA(
[](TabBinding* element_binding, UiBrowserInterface* browser,
bool incognito, const int& id) {
static_cast<Button*>(element_binding->view()->GetDescendantByType(
kTypeTabItemRemoveButton))
->set_click_handler(base::BindRepeating(
[](UiBrowserInterface* browser, int id, bool incognito) {
browser->CloseTab(id, incognito);
},
base::Unretained(browser), id, incognito));
},
base::Unretained(element_binding), base::Unretained(browser),
incognito)));
shadow->set_shadow_caster(remove_button->background());
shadow->AddBinding(std::make_unique<Binding<bool>>(
VR_BIND_LAMBDA(
[](Button* item, Button* remove_button) {
return item->hovered() || remove_button->hovered();
},
base::Unretained(item.get()), base::Unretained(remove_button.get())),
VR_BIND_LAMBDA([](UiElement* shadow,
const bool& hovered) { shadow->SetVisible(hovered); },
base::Unretained(shadow.get()))));
shadow->AddChild(std::move(remove_button));
item->background()->AddChild(std::move(shadow));
element_binding->set_view(item.get());
scene->AddUiElement(tabs_view, std::move(item)); scene->AddUiElement(tabs_view, std::move(item));
} }
......
...@@ -1350,52 +1350,4 @@ TEST_F(UiTest, LongPressAppButtonInWebVrMode) { ...@@ -1350,52 +1350,4 @@ TEST_F(UiTest, LongPressAppButtonInWebVrMode) {
EXPECT_FALSE(IsVisible(kWebVrExclusiveScreenToast)); EXPECT_FALSE(IsVisible(kWebVrExclusiveScreenToast));
} }
TEST_F(UiTest, VerifyAllElementNamesAndTypesAreUsed) {
UiInitialState state;
state.in_cct = false;
state.in_web_vr = false;
state.create_tabs_view = true;
CreateScene(state);
// Add an omnibox suggestion (a dynamically-created element).
model_->omnibox_suggestions.emplace_back(OmniboxSuggestion());
model_->push_mode(kModeEditingOmnibox);
OnBeginFrame();
// Build the set of available names and types.
std::set<UiElementName> names;
for (int i = UiElementName::kNone + 1; i < UiElementName::kNumUiElementNames;
i++) {
names.insert(static_cast<UiElementName>(i));
}
std::set<UiElementType> types;
for (int i = UiElementType::kTypeNone + 1;
i < UiElementType::kNumUiElementTypes; i++) {
types.insert(static_cast<UiElementType>(i));
}
// Remove names and types used by elements, and detect duplicates.
auto elements = scene_->GetAllElements();
for (auto* element : elements) {
if (element->name() != kNone) {
bool available = (names.find(element->name()) != names.end());
EXPECT_TRUE(available) << UiElementNameToString(element->name());
if (available) {
names.erase(element->name());
}
}
if (element->type() != kTypeNone) {
bool available = (types.find(element->type()) != types.end());
if (available) {
types.erase(element->type());
}
}
}
for (auto unused : names)
EXPECT_FALSE(true) << UiElementNameToString(unused);
for (auto unused : types)
EXPECT_FALSE(true) << UiElementTypeToString(unused);
}
} // namespace vr } // namespace vr
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment