[gnome-documents] preview: move all fullscreen preview code to PreviewEmbed
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] preview: move all fullscreen preview code to PreviewEmbed
- Date: Mon, 30 Apr 2012 22:26:52 +0000 (UTC)
commit 4f965aaff6901578f61fab7a89bb4aa9a05b99eb
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Mar 24 19:42:35 2012 -0400
preview: move all fullscreen preview code to PreviewEmbed
Simplifies code in Embed and delegates to the preview object the
fullscreen tasks.
src/embed.js | 86 ++----------------------------------------------
src/preview.js | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 92 insertions(+), 92 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index f78fd53..028610d 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -42,7 +42,6 @@ const Gtk = imports.gi.Gtk;
const GtkClutter = imports.gi.GtkClutter;
const _PDF_LOADER_TIMEOUT = 400;
-const _FULLSCREEN_TOOLBAR_TIMEOUT = 2;
function ViewEmbed() {
this._init();
@@ -53,16 +52,12 @@ ViewEmbed.prototype = {
this._adjustmentValueId = 0;
this._adjustmentChangedId = 0;
this._loaderCancellable = null;
- this._motionTimeoutId = 0;
this._queryErrorId = 0;
this._scrollbarVisibleId = 0;
this._scrolledWinView = null;
this._scrolledWinPreview = null;
- this._filter = new Gd.FullscreenFilter();
- this._filter.connect('motion-event', Lang.bind(this, this._fullscreenMotionHandler));
-
// the embed is a vertical ClutterBox
this._overlayLayout = new Clutter.BinLayout();
this.actor = new Clutter.Box({ layout_manager: this._overlayLayout });
@@ -170,61 +165,18 @@ ViewEmbed.prototype = {
},
_onFullscreenChanged: function(controller, fullscreen) {
- if (this._motionTimeoutId != 0) {
- Mainloop.source_remove(this._motionTimeoutId);
- this._motionTimeoutId = 0;
- }
-
if (fullscreen) {
- this._filter.start();
+ this._previewEmbed = new Preview.PreviewEmbed(this._docModel,
+ this._overlayLayout, this._contentsActor, this._scrolledWinPreview);
} else {
- this._filter.stop();
-
- this._destroyFullscreenToolbar();
- this._destroyPreviewEmbed();
+ this._previewEmbed.destroy();
+ this._previewEmbed = null;
}
Gtk.Settings.get_default().gtk_application_prefer_dark_theme = fullscreen;
this._toolbar.widget.visible = !fullscreen;
},
- _createFullscreenToolbar: function() {
- this._fsToolbar = new MainToolbar.FullscreenToolbar();
- this._fsToolbar.setModel(this._docModel);
-
- this._overlayLayout.add(this._fsToolbar.actor,
- Clutter.BinAlignment.FIXED, Clutter.BinAlignment.FIXED);
-
- let vScrollbar = this._scrolledWinPreview.get_vscrollbar();
-
- let sizeConstraint = new Clutter.BindConstraint
- ({ coordinate: Clutter.BindCoordinate.WIDTH,
- source: this.actor,
- offset: (vScrollbar.get_visible() ?
- (- (vScrollbar.get_preferred_width()[1])) : 0 ) });
-
- // update the constraint size when the scrollbar changes visibility
- vScrollbar.connect('notify::visible',
- function() {
- sizeConstraint.offset = (vScrollbar.get_visible() ?
- (- (vScrollbar.get_preferred_width()[1])) : 0 );
- });
-
- this._fsToolbar.actor.add_constraint(sizeConstraint);
- },
-
- _destroyFullscreenToolbar: function() {
- this._fsToolbar.widget.destroy();
- this._fsToolbar = null;
- },
-
- _destroyPreviewEmbed: function() {
- if (this._previewEmbed) {
- this._previewEmbed.actor.destroy();
- this._previewEmbed = null;
- }
- },
-
_moveOutBackground: function() {
Tweener.addTween(this._background, { opacity: 0,
time: 0.20,
@@ -312,41 +264,11 @@ ViewEmbed.prototype = {
this._spinnerBox.moveOut();
Global.modeController.setCanFullscreen(true);
this._preview = new Preview.PreviewView(this._docModel);
- this._previewEmbed = new Preview.PreviewEmbed(this._docModel,
- this._overlayLayout, this._contentsActor);
- this._createFullscreenToolbar();
this._scrolledWinPreview.add(this._preview.widget);
this._preview.widget.grab_focus();
},
- _fullscreenMotionHandler: function() {
- if (!Global.modeController.getFullscreen())
- return;
-
- // if we were idle fade in the toolbar, otherwise reset
- // the timeout
- if (this._motionTimeoutId == 0) {
- this._fsToolbar.show();
- this._previewEmbed.thumbBar.show();
- } else {
- Mainloop.source_remove(this._motionTimeoutId);
- }
-
- this._motionTimeoutId = Mainloop.timeout_add_seconds
- (_FULLSCREEN_TOOLBAR_TIMEOUT, Lang.bind(this,
- function() {
- this._motionTimeoutId = 0;
-
- if (this._fsToolbar)
- this._fsToolbar.hide();
-
- this._previewEmbed.thumbBar.hide();
-
- return false;
- }));
- },
-
_prepareForOverview: function() {
this._destroyPreview();
diff --git a/src/preview.js b/src/preview.js
index 7530aa5..b699a53 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -27,11 +27,15 @@ const Gtk = imports.gi.Gtk;
const GtkClutter = imports.gi.GtkClutter;
const Lang = imports.lang;
+const Mainloop = imports.mainloop;
const Global = imports.global;
const Tweener = imports.util.tweener;
+const MainToolbar = imports.mainToolbar;
const View = imports.view;
+const _FULLSCREEN_TOOLBAR_TIMEOUT = 2; // seconds
+
function PreviewView(model) {
this._init(model);
}
@@ -149,27 +153,33 @@ PreviewThumbnails.prototype = {
}
};
-function PreviewEmbed(model, layout, parentActor) {
- this._init(model, layout, parentActor);
+function PreviewEmbed(model, layout, parentActor, scrolledWindow) {
+ this._init(model, layout, parentActor, scrolledWindow);
}
PreviewEmbed.prototype = {
- _init: function(model, layout, parentActor) {
+ _init: function(model, layout, parentActor, scrolledWindow) {
this._layout = layout;
this._parentActor = parentActor;
+ this._previewScrolledWindow = scrolledWindow;
+ this._motionTimeoutId = 0;
+
+ this._filter = new Gd.FullscreenFilter();
+ this._filter.connect('motion-event', Lang.bind(this, this._fullscreenMotionHandler));
+ this._filter.start();
- this.thumbBar = new PreviewThumbnails(model);
- this.actor = this.thumbBar.actor;
+ // create thumb bar
+ this._thumbBar = new PreviewThumbnails(model);
- this._layout.add(this.actor,
+ this._layout.add(this._thumbBar.actor,
Clutter.BinAlignment.FIXED, Clutter.BinAlignment.FIXED);
let widthConstraint =
new Clutter.BindConstraint({ source: this._parentActor,
coordinate: Clutter.BindCoordinate.WIDTH,
offset: - 300 });
- this.actor.add_constraint(widthConstraint);
- this.actor.connect('notify::width', Lang.bind(this,
+ this._thumbBar.actor.add_constraint(widthConstraint);
+ this._thumbBar.actor.connect('notify::width', Lang.bind(this,
function() {
let width = this._parentActor.width;
let offset = 300;
@@ -182,13 +192,81 @@ PreviewEmbed.prototype = {
widthConstraint.offset = - offset;
}));
- this.actor.add_constraint(
+ this._thumbBar.actor.add_constraint(
new Clutter.AlignConstraint({ align_axis: Clutter.AlignAxis.X_AXIS,
source: this._parentActor,
factor: 0.50 }));
- this.actor.add_constraint(
+ this._thumbBar.actor.add_constraint(
new Clutter.AlignConstraint({ align_axis: Clutter.AlignAxis.Y_AXIS,
source: this._parentActor,
factor: 0.95 }));
+
+ // create toolbar
+ this._fsToolbar = new MainToolbar.FullscreenToolbar();
+ this._fsToolbar.setModel(model);
+
+ this._layout.add(this._fsToolbar.actor,
+ Clutter.BinAlignment.FIXED, Clutter.BinAlignment.FIXED);
+
+ let vScrollbar = this._previewScrolledWindow.get_vscrollbar();
+
+ let sizeConstraint = new Clutter.BindConstraint
+ ({ coordinate: Clutter.BindCoordinate.WIDTH,
+ source: this._parentActor,
+ offset: (vScrollbar.get_visible() ?
+ (- (vScrollbar.get_preferred_width()[1])) : 0 ) });
+
+ // update the constraint size when the scrollbar changes visibility
+ vScrollbar.connect('notify::visible',
+ function() {
+ sizeConstraint.offset = (vScrollbar.get_visible() ?
+ (- (vScrollbar.get_preferred_width()[1])) : 0 );
+ });
+
+ this._fsToolbar.actor.add_constraint(sizeConstraint);
+ },
+
+ destroy: function() {
+ if (this._motionTimeoutId != 0) {
+ Mainloop.source_remove(this._motionTimeoutId);
+ this._motionTimeoutId = 0;
+ }
+
+ this._filter.stop();
+
+ this._thumbBar.actor.destroy();
+ this._fsToolbar.widget.destroy();
+ },
+
+ _show: function() {
+ this._fsToolbar.show();
+ this._thumbBar.show();
+ },
+
+ _hide: function() {
+ this._fsToolbar.hide();
+ this._thumbBar.hide();
+ },
+
+ _fullscreenMotionHandler: function() {
+ if (!Global.modeController.getFullscreen())
+ return;
+
+ // if we were idle fade in the toolbar, otherwise reset
+ // the timeout
+ if (this._motionTimeoutId == 0) {
+ this._show();
+ } else {
+ Mainloop.source_remove(this._motionTimeoutId);
+ }
+
+ this._motionTimeoutId = Mainloop.timeout_add_seconds
+ (_FULLSCREEN_TOOLBAR_TIMEOUT, Lang.bind(this,
+ function() {
+ this._motionTimeoutId = 0;
+ this._hide();
+
+ return false;
+ }));
}
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]