summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorjamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-31 01:34:10 +0000
committerjamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-31 01:34:10 +0000
commitf8c9f8295f9eaadd99fd63607916770168db9aa2 (patch)
tree94827e93db5e023859c30d5255c4cee888d2032a /remoting
parent06e85dfda8d84354185ce783f9b0fb417e3d7aa8 (diff)
downloadchromium_src-f8c9f8295f9eaadd99fd63607916770168db9aa2.zip
chromium_src-f8c9f8295f9eaadd99fd63607916770168db9aa2.tar.gz
chromium_src-f8c9f8295f9eaadd99fd63607916770168db9aa2.tar.bz2
Resize host desktop to match client dimensions.
This allows a remote user to make best use of their desktop, without needing either to scroll around it or to scale it down to fit their client device. BUG=110212 Review URL: https://chromiumcodereview.appspot.com/11336024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165086 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/resizing_host_observer.cc24
-rw-r--r--remoting/host/resizing_host_observer.h5
2 files changed, 16 insertions, 13 deletions
diff --git a/remoting/host/resizing_host_observer.cc b/remoting/host/resizing_host_observer.cc
index ba419512..27f8abf 100644
--- a/remoting/host/resizing_host_observer.cc
+++ b/remoting/host/resizing_host_observer.cc
@@ -17,13 +17,13 @@ ResizingHostObserver::ResizingHostObserver(
host_(host),
original_size_(SkISize::Make(0, 0)),
previous_size_(SkISize::Make(0, 0)) {
- if (host_) {
+ if (host_ != NULL) {
host_->AddStatusObserver(this);
}
}
ResizingHostObserver::~ResizingHostObserver() {
- if (host_) {
+ if (host_ != NULL) {
host_->RemoveStatusObserver(this);
}
}
@@ -48,15 +48,19 @@ class CandidateSize {
public:
CandidateSize(const SkISize& candidate, const SkISize& preferred)
: size_(candidate) {
+ // Protect against division by zero.
+ CHECK(!candidate.isEmpty());
+ DCHECK(!preferred.isEmpty());
+
// The client scale factor is the smaller of the candidate:preferred ratios
// for width and height.
if ((candidate.width() > preferred.width()) ||
(candidate.height() > preferred.height())) {
- float ratio_width =
+ const float width_ratio =
static_cast<float>(preferred.width()) / candidate.width();
- float ratio_height =
+ const float height_ratio =
static_cast<float>(preferred.height()) / candidate.height();
- client_scale_factor_ = std::min(ratio_width, ratio_height);
+ client_scale_factor_ = std::min(width_ratio, height_ratio);
} else {
// Since clients do not scale up, 1.0 is the maximum.
client_scale_factor_ = 1.0;
@@ -66,7 +70,7 @@ class CandidateSize {
// of the two aspect ratios (candidate and preferred) to the larger. The
// best aspect ratio is the one that most closely matches the preferred
// aspect ratio (in other words, the ideal aspect ratio "goodness" is 1.0).
- // By keeping the values < 1.0, it allows ratios the differ in opposite
+ // By keeping the values < 1.0, it allows ratios that differ in opposite
// directions to be compared numerically.
float candidate_aspect_ratio =
static_cast<float>(candidate.width()) / candidate.height();
@@ -112,7 +116,7 @@ class CandidateSize {
// If the aspect ratios are equally good (for example, comparing 640x480
// to 480x640 w.r.t. 640x640), just pick the widest, since desktop UIs
- // are typically design for landscape aspect ratios.
+ // are typically designed for landscape aspect ratios.
return size().width() > other.size().width();
}
@@ -124,7 +128,7 @@ class CandidateSize {
void ResizingHostObserver::OnClientDimensionsChanged(
const std::string& jid, const SkISize& preferred_size) {
- if (previous_size_.isZero()) {
+ if (previous_size_.isZero() || preferred_size.isEmpty()) {
return;
}
@@ -145,8 +149,8 @@ void ResizingHostObserver::OnClientDimensionsChanged(
return;
}
CandidateSize best_size(sizes.front(), preferred_size);
- std::list<SkISize>::iterator i = sizes.begin();
- for (++i; i != sizes.end(); ++i) {
+ for (std::list<SkISize>::const_iterator i = ++sizes.begin();
+ i != sizes.end(); ++i) {
CandidateSize candidate_size(*i, preferred_size);
if (candidate_size.IsBetterThan(best_size)) {
best_size = candidate_size;
diff --git a/remoting/host/resizing_host_observer.h b/remoting/host/resizing_host_observer.h
index cdafa89..41b18fe 100644
--- a/remoting/host/resizing_host_observer.h
+++ b/remoting/host/resizing_host_observer.h
@@ -23,8 +23,7 @@ class DesktopResizer;
// the original desktop size.
class ResizingHostObserver : public HostStatusObserver {
public:
- explicit ResizingHostObserver(DesktopResizer* desktop_resizer,
- ChromotingHost* host);
+ ResizingHostObserver(DesktopResizer* desktop_resizer, ChromotingHost* host);
virtual ~ResizingHostObserver();
// HostStatusObserver interface
@@ -34,7 +33,7 @@ class ResizingHostObserver : public HostStatusObserver {
const SkISize& size) OVERRIDE;
private:
- DesktopResizer* desktop_resizer_;
+ DesktopResizer* const desktop_resizer_;
scoped_refptr<ChromotingHost> host_;
SkISize original_size_;
SkISize previous_size_;