Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal-browser
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 114d3aaaa7eb
Choose a base ref
...
head repository: opal/opal-browser
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4ea7af133a9b
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jan 21, 2014

  1. Copy the full SHA
    acf27fa View commit details
  2. socket: add references

    meh committed Jan 21, 2014
    Copy the full SHA
    4ea7af1 View commit details
Showing with 36 additions and 6 deletions.
  1. +31 −5 opal/browser/screen.rb
  2. +5 −1 opal/browser/socket.rb
36 changes: 31 additions & 5 deletions opal/browser/screen.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module Browser

# Representation of the screen the window is being rendered on.
#
# @see https://developer.mozilla.org/en-US/docs/Web/API/Window.screen
class Screen
include Native
include DOM::Event::Target
@@ -8,30 +11,53 @@ class Screen
Screen.new(value) if Native.is_a?(value, `window.Screen`)
}

Depth = Struct.new(:color, :pixel)

# @!attribute [r] width
# @return [Integer] the width of the screen in pixels
alias_native :width

# @!attribute [r] height
# @return [Integer] the height of the screen in pixels
alias_native :height

# @!attribute [r] size
# @return [Size] the size in pixels
def size
Size.new(width, height)
end

# @!attribute [r] x
# @return [Integer] the offset from the top left corner of the screen in
# pixels
alias_native :x, :top

# @!attribute [r] y
# @return [Integer] the offset from the top left corner of the screen in
# pixels
alias_native :y, :left

# @!attribute [r] position
# @return [Position] the offset from the top left corner of the screen in
# pixels
def position
Position.new(x, y)
end

alias_native :color_depth, :colorDepth
alias_native :pixel_depth, :pixelDepth
# @!attribute [r] depth
# @return [Depth] the screen depth
def depth
Depth.new(`#@native.colorDepth`, `#@native.pixelDepth`)
end

# @!attribute [r] orientation
# @return [String] the orientation of the screen
alias_native :orientation
end

class Window
# Get the {Screen} for this window.
#
# @return [Screen]
# @!attribute [r] screen
# @return [Screen] the screen for the window
def screen
Screen.new(`#@native.screen`)
end
6 changes: 5 additions & 1 deletion opal/browser/socket.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module Browser

# This class wraps `WebSocket`.
# A {Socket} allows the browser and a server to have a bidirectional data
# connection.
#
# @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
class Socket
def self.supported?
defined? `window.WebSocket`
@@ -18,6 +21,7 @@ def self.supported?
#
# @param url [String] the URL to connect to
# @param protocol [String] the protocol to use
#
# @yield if the block has no parameters it's instance_exec'd, otherwise it's
# called with self
def initialize(url, protocol = nil, &block)