diff options
author | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-24 11:06:51 +0000 |
---|---|---|
committer | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-24 11:06:51 +0000 |
commit | f48075d2a17ae6311521745412f58984ea3c8f29 (patch) | |
tree | 99e5a77417805e9c3b30ec2b321187fa0c227c98 | |
parent | d94141654a3e6794865653c92ffd3b053e983815 (diff) | |
download | chromium_src-f48075d2a17ae6311521745412f58984ea3c8f29.zip chromium_src-f48075d2a17ae6311521745412f58984ea3c8f29.tar.gz chromium_src-f48075d2a17ae6311521745412f58984ea3c8f29.tar.bz2 |
Reland 138212
Implement High Contrast mode for Chrome OS.
-Add controller to ash for managing the state of High Contrast mode
-Add API to shell to allow Chromium to turn the mode on and off
-Add the option to the Chromium OS accessibility settings page.
-Add functions to layer.cc/h to enable an inversion filter.
TBR=sky@chromium.org,jhawkins@chromium.org
BUG=chromium-os:30678
Review URL: https://chromiumcodereview.appspot.com/10408085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138771 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/high_contrast/high_contrast_controller.cc | 24 | ||||
-rw-r--r-- | ash/high_contrast/high_contrast_controller.h | 36 | ||||
-rw-r--r-- | ash/shell.cc | 2 | ||||
-rw-r--r-- | ash/shell.h | 7 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main_extra_parts_ash.cc | 5 | ||||
-rw-r--r-- | chrome/browser/chromeos/accessibility/accessibility_util.cc | 16 | ||||
-rw-r--r-- | chrome/browser/chromeos/accessibility/accessibility_util.h | 3 | ||||
-rw-r--r-- | chrome/browser/resources/options2/browser_options.html | 8 | ||||
-rw-r--r-- | chrome/browser/resources/options2/browser_options.js | 9 | ||||
-rw-r--r-- | ui/compositor/layer.cc | 21 | ||||
-rw-r--r-- | ui/compositor/layer.h | 5 |
12 files changed, 134 insertions, 4 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 856001f..601b329 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -67,6 +67,8 @@ 'drag_drop/drag_image_view.h', 'focus_cycler.cc', 'focus_cycler.h', + 'high_contrast/high_contrast_controller.cc', + 'high_contrast/high_contrast_controller.h', 'key_rewriter_delegate.h', 'launcher/background_animator.cc', 'launcher/background_animator.h', diff --git a/ash/high_contrast/high_contrast_controller.cc b/ash/high_contrast/high_contrast_controller.cc new file mode 100644 index 0000000..b501fc9 --- /dev/null +++ b/ash/high_contrast/high_contrast_controller.cc @@ -0,0 +1,24 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/high_contrast/high_contrast_controller.h" + +#include "ash/shell.h" +#include "ui/aura/root_window.h" +#include "ui/compositor/layer.h" + +namespace ash { + +HighContrastController::HighContrastController() + : enabled_(false) { + root_window_ = ash::Shell::GetRootWindow(); +} + +void HighContrastController::SetEnabled(bool enabled) { + enabled_ = enabled; + + root_window_->layer()->SetInverted(enabled_); +} + +} // namespace ash diff --git a/ash/high_contrast/high_contrast_controller.h b/ash/high_contrast/high_contrast_controller.h new file mode 100644 index 0000000..b5b589f --- /dev/null +++ b/ash/high_contrast/high_contrast_controller.h @@ -0,0 +1,36 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_HIGH_CONTRAST_HIGH_CONTRAST_CONTROLLER_H_ +#define ASH_HIGH_CONTRAST_HIGH_CONTRAST_CONTROLLER_H_ +#pragma once + +#include "ash/ash_export.h" +#include "base/basictypes.h" + +namespace aura { +class RootWindow; +} + +namespace ash { + +class ASH_EXPORT HighContrastController { + public: + HighContrastController(); + + ~HighContrastController() {} + + void SetEnabled(bool enabled); + + private: + aura::RootWindow* root_window_; + + bool enabled_; + + DISALLOW_COPY_AND_ASSIGN(HighContrastController); +}; + +} // namespace ash + +#endif // ASH_HIGH_CONTRAST_HIGH_CONTRAST_CONTROLLER_H_ diff --git a/ash/shell.cc b/ash/shell.cc index d1b532a..9e10445 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -14,6 +14,7 @@ #include "ash/desktop_background/desktop_background_view.h" #include "ash/drag_drop/drag_drop_controller.h" #include "ash/focus_cycler.h" +#include "ash/high_contrast/high_contrast_controller.h" #include "ash/launcher/launcher.h" #include "ash/magnifier/magnification_controller.h" #include "ash/monitor/monitor_controller.h" @@ -758,6 +759,7 @@ void Shell::Init() { drag_drop_controller_.reset(new internal::DragDropController); magnification_controller_.reset(new internal::MagnificationController); + high_contrast_controller_.reset(new HighContrastController); power_button_controller_.reset(new PowerButtonController); AddShellObserver(power_button_controller_.get()); video_detector_.reset(new VideoDetector); diff --git a/ash/shell.h b/ash/shell.h index ca2e91e..fa8c50d 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -53,6 +53,7 @@ namespace ash { class AcceleratorController; class DesktopBackgroundController; +class HighContrastController; class Launcher; class NestedDispatcherController; class PowerButtonController; @@ -237,9 +238,14 @@ class ASH_EXPORT Shell { return user_wallpaper_delegate_.get(); } + HighContrastController* high_contrast_controller() { + return high_contrast_controller_.get(); + } + internal::MagnificationController* magnification_controller() { return magnification_controller_.get(); } + internal::ScreenDimmer* screen_dimmer() { return screen_dimmer_.get(); } @@ -348,6 +354,7 @@ class ASH_EXPORT Shell { scoped_ptr<internal::FocusCycler> focus_cycler_; scoped_ptr<internal::EventClientImpl> event_client_; scoped_ptr<internal::MonitorController> monitor_controller_; + scoped_ptr<HighContrastController> high_contrast_controller_; scoped_ptr<internal::MagnificationController> magnification_controller_; scoped_ptr<internal::ScreenDimmer> screen_dimmer_; diff --git a/chrome/browser/chrome_browser_main_extra_parts_ash.cc b/chrome/browser/chrome_browser_main_extra_parts_ash.cc index cf529c9..a353a6f 100644 --- a/chrome/browser/chrome_browser_main_extra_parts_ash.cc +++ b/chrome/browser/chrome_browser_main_extra_parts_ash.cc @@ -6,10 +6,12 @@ #include "ash/accelerators/accelerator_controller.h" #include "ash/ash_switches.h" +#include "ash/high_contrast/high_contrast_controller.h" #include "ash/shell.h" #include "ash/wm/key_rewriter_event_filter.h" #include "ash/wm/property_util.h" #include "base/command_line.h" +#include "chrome/browser/chromeos/accessibility/accessibility_util.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/ui/views/ash/caps_lock_handler.h" #include "chrome/browser/ui/views/ash/chrome_shell_delegate.h" @@ -76,6 +78,9 @@ void ChromeBrowserMainExtraPartsAsh::PreProfileInit() { shell->accelerator_controller()->SetVolumeControlDelegate( scoped_ptr<ash::VolumeControlDelegate>(new VolumeController).Pass()); + ash::Shell::GetInstance()->high_contrast_controller()->SetEnabled( + chromeos::accessibility::IsHighContrastEnabled()); + if (!CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisableZeroBrowsersOpenForTests)) { browser::StartKeepAlive(); diff --git a/chrome/browser/chromeos/accessibility/accessibility_util.cc b/chrome/browser/chromeos/accessibility/accessibility_util.cc index 9704d35..253efe6 100644 --- a/chrome/browser/chromeos/accessibility/accessibility_util.cc +++ b/chrome/browser/chromeos/accessibility/accessibility_util.cc @@ -6,6 +6,8 @@ #include <queue> +#include "ash/high_contrast/high_contrast_controller.h" +#include "ash/shell.h" #include "base/bind.h" #include "base/bind_helpers.h" #include "base/logging.h" @@ -164,6 +166,10 @@ void EnableHighContrast(bool enabled) { PrefService* pref_service = g_browser_process->local_state(); pref_service->SetBoolean(prefs::kHighContrastEnabled, enabled); pref_service->CommitPendingWrite(); + +#if defined(USE_ASH) + ash::Shell::GetInstance()->high_contrast_controller()->SetEnabled(enabled); +#endif } void EnableScreenMagnifier(bool enabled) { @@ -205,6 +211,16 @@ bool IsSpokenFeedbackEnabled() { return spoken_feedback_enabled; } +bool IsHighContrastEnabled() { + if (!g_browser_process) { + return false; + } + PrefService* prefs = g_browser_process->local_state(); + bool high_contrast_enabled = prefs && + prefs->GetBoolean(prefs::kHighContrastEnabled); + return high_contrast_enabled; +} + void MaybeSpeak(const std::string& utterance) { if (IsSpokenFeedbackEnabled()) Speak(utterance); diff --git a/chrome/browser/chromeos/accessibility/accessibility_util.h b/chrome/browser/chromeos/accessibility/accessibility_util.h index 44094f1..ad65818 100644 --- a/chrome/browser/chromeos/accessibility/accessibility_util.h +++ b/chrome/browser/chromeos/accessibility/accessibility_util.h @@ -40,6 +40,9 @@ void Speak(const std::string& utterance); // Returns true if spoken feedback is enabled, or false if not. bool IsSpokenFeedbackEnabled(); +// Returns true if High Contrast is enabled, or false if not. +bool IsHighContrastEnabled(); + // Speak the given text if the accessibility pref is already set. void MaybeSpeak(const std::string& utterance); diff --git a/chrome/browser/resources/options2/browser_options.html b/chrome/browser/resources/options2/browser_options.html index a5d86b4..7284b53 100644 --- a/chrome/browser/resources/options2/browser_options.html +++ b/chrome/browser/resources/options2/browser_options.html @@ -489,6 +489,14 @@ </label> </div> </div> + <div class="option-name"> + <div class="checkbox"> + <label> + <input id="accessibility-high-contrast-check" type="checkbox"> + <span i18n-content="accessibilityHighContrast"></span> + </label> + </div> + </div> </div> </section> </if> diff --git a/chrome/browser/resources/options2/browser_options.js b/chrome/browser/resources/options2/browser_options.js index 247ee65..7567ac2 100644 --- a/chrome/browser/resources/options2/browser_options.js +++ b/chrome/browser/resources/options2/browser_options.js @@ -464,7 +464,12 @@ cr.define('options', function() { if (cr.isChromeOS) { $('accessibility-spoken-feedback-check').onchange = function(event) { chrome.send('spokenFeedbackChange', - [$('accessibility-spoken-feedback-check').checked]); + [$('accessibility-spoken-feedback-check').checked]); + }; + + $('accessibility-high-contrast-check').onchange = function(event) { + chrome.send('highContrastChange', + [$('accessibility-high-contrast-check').checked]); }; } @@ -1212,7 +1217,7 @@ cr.define('options', function() { * @private */ setHighContrastCheckboxState_: function(checked) { - // TODO(zork): Update UI + $('accessibility-high-contrast-check').checked = checked; }, /** diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc index d5f0c44..6883270 100644 --- a/ui/compositor/layer.cc +++ b/ui/compositor/layer.cc @@ -52,6 +52,7 @@ Layer::Layer() fills_bounds_opaquely_(true), layer_updated_externally_(false), opacity_(1.0f), + inverted_(false), delegate_(NULL), scale_content_(true), device_scale_factor_(1.0f) { @@ -66,6 +67,7 @@ Layer::Layer(LayerType type) fills_bounds_opaquely_(true), layer_updated_externally_(false), opacity_(1.0f), + inverted_(false), delegate_(NULL), scale_content_(true), device_scale_factor_(1.0f) { @@ -194,8 +196,7 @@ void Layer::SetOpacity(float opacity) { GetAnimator()->SetOpacity(opacity); } -void Layer::SetBackgroundBlur(int blur_radius) -{ +void Layer::SetBackgroundBlur(int blur_radius) { WebKit::WebFilterOperations filters; if (blur_radius) { #if WEBKIT_HAS_NEW_WEBFILTEROPERATION_API @@ -209,6 +210,22 @@ void Layer::SetBackgroundBlur(int blur_radius) background_blur_radius_ = blur_radius; } +void Layer::SetInverted(bool inverted) { + WebKit::WebFilterOperations filters; + if (inverted) { +#if WEBKIT_HAS_NEW_WEBFILTEROPERATION_API + filters.append(WebKit::WebFilterOperation::createInvertFilter(1.0)); +#else + filters.append(WebKit::WebBasicComponentTransferFilterOperation( + WebKit::WebBasicComponentTransferFilterOperation:: + BasicComponentTransferFilterTypeInvert, 1.0)); +#endif + } + web_layer_.setFilters(filters); + + inverted_ = inverted; +} + float Layer::GetTargetOpacity() const { if (animator_.get() && animator_->IsAnimatingProperty( LayerAnimationElement::OPACITY)) diff --git a/ui/compositor/layer.h b/ui/compositor/layer.h index d19fe07..22efe58 100644 --- a/ui/compositor/layer.h +++ b/ui/compositor/layer.h @@ -134,6 +134,10 @@ class COMPOSITOR_EXPORT Layer : int background_blur() const { return background_blur_radius_; } void SetBackgroundBlur(int blur_radius); + // Invert the layer. + bool inverted() const { return inverted_; } + void SetInverted(bool inverted); + // Return the target opacity if animator is running, or the current opacity // otherwise. float GetTargetOpacity() const; @@ -290,6 +294,7 @@ class COMPOSITOR_EXPORT Layer : float opacity_; int background_blur_radius_; + bool inverted_; std::string name_; |