Last Comment Bug 641906 - Use system theme colors in nsLookAndFeel on Android
: Use system theme colors in nsLookAndFeel on Android
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: Widget: Android (show other bugs)
: Trunk
: All Android
: -- normal (vote)
: mozilla6
Assigned To: Alex Pakhotin (:alexp)
:
Mentors:
: 610632 (view as bug list)
Depends on:
Blocks: 647338
  Show dependency treegraph
 
Reported: 2011-03-15 11:23 PDT by Alex Pakhotin (:alexp)
Modified: 2011-07-14 21:37 PDT (History)
8 users (show)
bzbarsky: in‑testsuite?
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
fixed
6+


Attachments
[WIP] Get some system colors (10.37 KB, patch)
2011-03-19 00:09 PDT, Alex Pakhotin (:alexp)
no flags Details | Diff | Review
Use the colors from the system (21.63 KB, patch)
2011-03-30 11:14 PDT, Alex Pakhotin (:alexp)
blassey.bugs: review+
Details | Diff | Review
Fix v3 (21.55 KB, patch)
2011-04-11 11:48 PDT, Alex Pakhotin (:alexp)
no flags Details | Diff | Review
Fix v4 - no crash (22.44 KB, patch)
2011-04-21 22:55 PDT, Alex Pakhotin (:alexp)
no flags Details | Diff | Review
[WIP] Made it work in the content process (6.83 KB, patch)
2011-04-26 18:10 PDT, Alex Pakhotin (:alexp)
no flags Details | Diff | Review
Fix v5 (26.93 KB, patch)
2011-04-27 17:11 PDT, Alex Pakhotin (:alexp)
blassey.bugs: review-
Details | Diff | Review
Fix v6 (26.77 KB, patch)
2011-04-29 18:52 PDT, Alex Pakhotin (:alexp)
blassey.bugs: review+
Details | Diff | Review
Fix v6 (final) (26.74 KB, patch)
2011-05-05 14:03 PDT, Alex Pakhotin (:alexp)
alex.mozilla: review+
Details | Diff | Review

Description Alex Pakhotin (:alexp) 2011-03-15 11:23:28 PDT
Current implementation of nsLookAndFeel on Android has all the colors hard-coded.
We should get them from the system instead.
Comment 1 Alex Pakhotin (:alexp) 2011-03-16 10:00:59 PDT
My first research shows that not many colors from the Android theme actually seem to be easily accessible. I am sure we won't find most of the colors defined in nsLookAndFeel list. I guess we need to match the base colors, and select our pre-defined theme which goes well with those.

What colors and other metrics defined in nsLookAndFeel list are really important, so they must correspond to the system theme?
http://mxr.mozilla.org/mozilla-central/source/widget/public/nsILookAndFeel.h
http://mxr.mozilla.org/mozilla-central/source/widget/src/android/nsLookAndFeel.cpp

At this point I can distinguish between the dark and light color schemes. We could use this information to select one of two our own schemes.
Comment 2 Brad Lassey [:blassey] (use needinfo?) 2011-03-17 22:50:40 PDT
Alex, here's an example of how to get the system's highlight color. This approach should be extendable to getting the other stuff nsLookAndFeel needs.

    public static int getHighlightColor() {
        int color = Color.rgb(0x83, 0xCF, 0xF1); // a default
        final ContextThemeWrapper contextThemeWrapper = 
            new ContextThemeWrapper(GeckoApp.mAppContext,
                                    android.R.style.TextAppearance);
        final TypedArray appearance = contextThemeWrapper.getTheme().
            obtainStyledAttributes(new int[]
            {android.R.attr.textColorHighlight});
        
        if (0 < appearance.getIndexCount()) {
            int attr = appearance.getIndex(0);
            color = appearance.getColor(attr, color);
            Log.i("GeckoResources", attr + " color: " + Color.red(color) +
                  ", " + Color.green(color) + ", " + Color.blue(color));
        }
        appearance.recycle();
        return color;
    }
Comment 3 Alex Pakhotin (:alexp) 2011-03-18 00:57:35 PDT
(In reply to comment #2)
> Alex, here's an example of how to get the system's highlight color.

Interesting... I was very close - tried basically the same approach, but in my case obtainStyledAttributes() returned some weird array.

Thank you - I'll use this way.
Comment 4 Brad Lassey [:blassey] (use needinfo?) 2011-03-18 13:13:40 PDT
*** Bug 610632 has been marked as a duplicate of this bug. ***
Comment 5 Alex Pakhotin (:alexp) 2011-03-19 00:09:45 PDT
Created attachment 520408 [details] [diff] [review]
[WIP] Get some system colors
Comment 6 Alex Pakhotin (:alexp) 2011-03-25 13:59:22 PDT
I did more experiments and investigation (including other systems). Right now it looks like only two colors from the nsLookAndFeel could be used in Fennec UI: eColor_graytext, and eColor__moz_dialog (actually used for the pages background before they load), when not overridden in the preferences. The rest seem to be defined in CSS.
We need to decide what colors we really need from the system, and get them specifically.

I'd recommend to get the colors on case-by-case basis, as some of them in Android theme are defined through attribute references, so they require additional processing in Java to get the actual color value. I'm sure we want to reduce the Java part of this as much as possible, as this code runs at startup, so we should process only necessary colors.
Comment 7 Mark Finkle (:mfinkle) (use needinfo?) 2011-03-25 14:26:05 PDT
I would get the code in place to handle any of the nsILookAndFeel colors or constants.

Yes, we do not use many "named" colors in Fennec at the moment. It's a chicken/egg problem. When you get a selection of Android colors available, we can start to use them by changing the CSS.

Off the top of my head, some colors and constants we care about:
* Font sizes - does Android tell us what the system font sizes for different UIs?
* Button text and background colors
* Dialog text and background colors (any other dialog styling too)
* Window test and background colors (preferences lists for example)
* Selection text and background colors
* Toaster popup text size, color and background color
* Progress bar color

These are the things that come to mind quickly.
Comment 8 Matt Brubeck (:mbrubeck) 2011-03-25 14:45:30 PDT
We'd also like to know background/foreground/highlight colors for the menu (the one that appears when you press the "Menu" system key), though I realize that like much of the Android skin these are partly images rather than flat colors.
Comment 9 Alex Pakhotin (:alexp) 2011-03-30 11:14:54 PDT
Created attachment 523060 [details] [diff] [review]
Use the colors from the system

Get the colors from the system theme in nsLookAndFeel, and make them available through nsILookAndFeel interface.

This is not an ideal implementation yet. The light theme currently used by Fennec has some inconsistencies, for example, both panelColorForeground and panelColorBackground are black, so apparently they cannot be used together. That's why in the current implementation colorForeground and colorBackground are used instead.
Comment 10 Brad Lassey [:blassey] (use needinfo?) 2011-04-07 11:53:48 PDT
Comment on attachment 523060 [details] [diff] [review]
Use the colors from the system

one nit, do the red and blue swap in the AndroidBridge method
Comment 11 Alex Pakhotin (:alexp) 2011-04-11 11:48:01 PDT
Created attachment 525120 [details] [diff] [review]
Fix v3

Moved color conversion to the AndroidBridge as suggested.

However, this still needs some debugging, as for some reason this patch (and the previous version as well) applied to the latest code somehow causes plugin-container process to crash.
Comment 12 Alex Pakhotin (:alexp) 2011-04-21 22:55:09 PDT
Created attachment 527723 [details] [diff] [review]
Fix v4 - no crash

It doesn't yet work in the content process (though not crashing anymore), but I think it'd be better to make that a separate bug, because it will require e10s-specific changes. A remote call implementation turned out to be a bit more tricky than expected - some interface changes might be needed.

Brad, if this patch looks good for you, let's submit this version, and I'll file a follow-up bug.
Comment 13 Alex Pakhotin (:alexp) 2011-04-26 18:10:53 PDT
Created attachment 528501 [details] [diff] [review]
[WIP] Made it work in the content process

Call LookAndFeel::GetColor remotely when in the content process.
Comment 14 Brad Lassey [:blassey] (use needinfo?) 2011-04-27 09:16:50 PDT
(In reply to comment #12)
> Created attachment 527723 [details] [diff] [review]
> Fix v4 - no crash
> 
> It doesn't yet work in the content process (though not crashing anymore), but I
> think it'd be better to make that a separate bug, because it will require
> e10s-specific changes. A remote call implementation turned out to be a bit more
> tricky than expected - some interface changes might be needed.
> 
> Brad, if this patch looks good for you, let's submit this version, and I'll
> file a follow-up bug.

I don't see a reason to land a patch that doesn't work for the content process at this point. Is there anything wrong with attachment 528501 [details] [diff] [review]?
Comment 15 Alex Pakhotin (:alexp) 2011-04-27 17:11:21 PDT
Created attachment 528754 [details] [diff] [review]
Fix v5

Remote call from the content process now gets all the colors in one batch.
Combined both patches into one.
Comment 16 Brad Lassey [:blassey] (use needinfo?) 2011-04-28 22:16:32 PDT
Comment on attachment 528754 [details] [diff] [review]
Fix v5

Review of attachment 528754 [details] [diff] [review]:

this is mostly good, but I'd like see a patch that uses a struct of nscolors before r+

::: dom/ipc/ContentParent.cpp
@@ +107,5 @@
 #include "nsISupportsPrimitives.h"
 static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
 static const char* sClipboardTextFlavors[] = { kUnicodeMime };
 
+static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);

I don't think you need to include nsILookAndFeel.h or define kLookAndFeeelCID

::: widget/src/android/AndroidBridge.cpp
@@ +681,5 @@
     GetJNIForThread()->CallStaticVoidMethod(mGeckoAppShellClass, jSetSelectedLocale, jLocale);
 }
 
 void
+AndroidBridge::GetSystemColors(nscolor* aColors, PRUint32& aLen)

might me nice to define a struct of nscolors to use here so the length is defined and the order is set

::: widget/src/android/nsLookAndFeel.cpp
@@ +71,5 @@
+    eSysColor_panelColorBackground,
+    eSysColor_count
+};
+
+static nscolor sSystemColors[eSysColor_count];

you'd use that struct of nscolors here rather than an array and an enumeration

@@ +84,5 @@
+#define ANDROID_HIGHLIGHT_COLOR                sSystemColors[eSysColor_textColorHighlight]
+#define ANDROID_FG_NORMAL_COLOR                sSystemColors[eSysColor_colorForeground]
+#define ANDROID_BG_NORMAL_COLOR                sSystemColors[eSysColor_colorBackground]
+#define ANDROID_FG_PANEL_COLOR                 sSystemColors[eSysColor_panelColorForeground]
+#define ANDROID_BG_PANEL_COLOR                 sSystemColors[eSysColor_panelColorBackground]

these defines seem unnecessary
Comment 17 Alex Pakhotin (:alexp) 2011-04-29 18:52:59 PDT
Created attachment 529254 [details] [diff] [review]
Fix v6

Used a structure instead of an array.
Comment 18 Brad Lassey [:blassey] (use needinfo?) 2011-05-02 19:40:56 PDT
Comment on attachment 529254 [details] [diff] [review]
Fix v6

Review of attachment 529254 [details] [diff] [review]:

r=blassey
Comment 19 Alex Pakhotin (:alexp) 2011-05-05 14:03:32 PDT
Created attachment 530424 [details] [diff] [review]
Fix v6 (final)

Updated to the latest code.
r=blassey
Comment 20 Boris Zbarsky [:bz] 2011-05-06 21:24:12 PDT
Pushed http://hg.mozilla.org/mozilla-central/rev/d6d104661d30
Comment 21 Paul [pwd] 2011-05-10 01:35:58 PDT
This landed some days ago and still I'm not seeing Fennec matching the colours of my theme for some reason.
Comment 22 Mark Finkle (:mfinkle) (use needinfo?) 2011-05-10 04:56:50 PDT
(In reply to comment #21)
> This landed some days ago and still I'm not seeing Fennec matching the
> colours of my theme for some reason.

Indeed. This patch only made it possible for the application to use the system colors. We still need to land other work (in other bugs) to actually make use of the system colors.
Comment 23 Paul [pwd] 2011-05-10 05:04:28 PDT
Thanks for clearing that up. Could you, if time permits, erect a dependency tree?

Note You need to log in before you can comment on or make changes to this bug.