Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ class GeckoEngine(
* Creates a new Gecko-based EngineView.
*/
override fun createView(context: Context, attrs: AttributeSet?): EngineView {
return GeckoEngineView(context, attrs)
return GeckoEngineView(context, attrs).apply {
setColorScheme(settings.preferredColorScheme)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
package mozilla.components.browser.engine.gecko

import android.content.Context
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.Color
import android.util.AttributeSet
import android.widget.FrameLayout
import androidx.annotation.VisibleForTesting
import androidx.core.view.ViewCompat
import mozilla.components.browser.engine.gecko.selection.GeckoSelectionActionDelegate
import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.engine.mediaquery.PreferredColorScheme
import mozilla.components.concept.engine.selection.SelectionActionDelegate
import org.mozilla.geckoview.BasicSelectionActionDelegate
import org.mozilla.geckoview.GeckoResult
Expand All @@ -38,7 +41,7 @@ class GeckoEngineView @JvmOverloads constructor(
val otherActivityClassName =
this.session?.accessibility?.view?.context?.javaClass?.simpleName
val otherActivityClassHashcode =
this.session?.accessibility?.view?.context?.hashCode()
this.session?.accessibility?.view?.context?.hashCode()
val activityClassName = context.javaClass.simpleName
val activityClassHashCode = context.hashCode()
val msg = "ATTACH VIEW: Current activity: $activityClassName hashcode " +
Expand All @@ -47,6 +50,7 @@ class GeckoEngineView @JvmOverloads constructor(
throw IllegalStateException(msg, e)
}
}

override fun onDetachedFromWindow() {
// We are releasing the session before GeckoView gets detached from the window. Otherwise
// GeckoView will close the session automatically and we do not want that.
Expand All @@ -61,6 +65,26 @@ class GeckoEngineView @JvmOverloads constructor(
ViewCompat.setImportantForAutofill(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES)
}

internal fun setColorScheme(preferredColorScheme: PreferredColorScheme) {
var colorScheme = preferredColorScheme
if (preferredColorScheme == PreferredColorScheme.System) {
colorScheme =
if (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
== Configuration.UI_MODE_NIGHT_YES
) {
PreferredColorScheme.Dark
} else {
PreferredColorScheme.Light
}
}

if (colorScheme == PreferredColorScheme.Dark) {
geckoView.coverUntilFirstPaint(DARK_COVER)
} else {
geckoView.coverUntilFirstPaint(Color.WHITE)
}
}

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal var currentSession: GeckoEngineSession? = null

Expand Down Expand Up @@ -142,7 +166,8 @@ class GeckoEngineView @JvmOverloads constructor(

override fun canScrollVerticallyUp() = currentSession?.let { it.scrollY > 0 } != false

override fun canScrollVerticallyDown() = true // waiting for this issue https://bugzilla.mozilla.org/show_bug.cgi?id=1507569
override fun canScrollVerticallyDown() =
true // waiting for this issue https://bugzilla.mozilla.org/show_bug.cgi?id=1507569

override fun getInputResult(): EngineView.InputResult {
// Direct mapping of GeckoView's returned values.
Expand Down Expand Up @@ -192,4 +217,8 @@ class GeckoEngineView @JvmOverloads constructor(
geckoView.visibility = visibility
super.setVisibility(visibility)
}

companion object {
internal const val DARK_COVER = 0xFF2A2A2E.toInt()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ package mozilla.components.browser.engine.gecko
import android.app.Activity
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Color
import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.browser.engine.gecko.GeckoEngineView.Companion.DARK_COVER
import mozilla.components.browser.engine.gecko.selection.GeckoSelectionActionDelegate
import mozilla.components.concept.engine.mediaquery.PreferredColorScheme
import mozilla.components.concept.engine.selection.SelectionActionDelegate
import mozilla.components.support.test.argumentCaptor
import mozilla.components.support.test.mock
Expand Down Expand Up @@ -104,6 +107,23 @@ class GeckoEngineViewTest {
verify(engineView.currentSelection)?.clearSelection()
}

@Test
fun `setColorScheme uses preferred color scheme to set correct cover color`() {
val engineView = GeckoEngineView(context)

engineView.geckoView = mock()

var preferredColorScheme: PreferredColorScheme = PreferredColorScheme.Light

engineView.setColorScheme(preferredColorScheme)

verify(engineView.geckoView)?.coverUntilFirstPaint(Color.WHITE)

preferredColorScheme = PreferredColorScheme.Dark
engineView.setColorScheme(preferredColorScheme)
verify(engineView.geckoView)?.coverUntilFirstPaint(DARK_COVER)
}

@Test
fun `setVerticalClipping is forwarded to GeckoView instance`() {
val engineView = GeckoEngineView(context)
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ permalink: /changelog/
* **feature-downloads**
* 🚒 Bug fixed [issue #8823](https://github.com/mozilla-mobile/android-components/issues/8823) Downloads for data URLs were failing on nightly and beta more details in the [Fenix issue](https://github.com/mozilla-mobile/fenix/issues/16228#issuecomment-717976737).

* **browser-engine-gecko-nightly**
* Adds optional `PreferredColorScheme` param to `GeckoEngineView`
* On `GeckoView` init call `coverUntilFirstPaint()` with `PreferredColorScheme`

# 64.0.0

* [Commits](https://github.com/mozilla-mobile/android-components/compare/v63.0.0...v64.0.0)
Expand Down